PHP preg_match - 正则表达式
PHP preg_match - regular expression
我有这段文字:
SU4R
C45G
G3HD
61U14XE7AR23 914K16W471LV V6SQ5V16LG91 24YL4HW956C3 UZ26J12K615V T741MH4N739W 31ST445G726H 621EH6VW7Q6M 55N629WJ945P 56TX2W6LC949 44DS765CF739 XC262HV1JZ6V 26YD4N1Y71F7 S4M3F1XeDC0D
我想使用 preg_match
在该文本中查找特定类型的代码,因此我应该包含:
- 4 或 12 个字符
- 它应该返回所有元素
- 不区分大小写
- 字母和数字
我已经结束了:
preg_match("/^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z!@#$%]{4,12}/", $input_line, $output_array);
但是:
- 它只适用于 http://www.phpliveregex.com/p/byZ
- 它只找到前 4 个元素
- 为什么当我尝试使用此页面时 https://www.functions-online.com/preg_match.html 它只显示 1 个匹配项?
使用 preg_match_all(),类似这样的方法可能有效
http://www.phpliveregex.com/p/bz0
# '/(?<!\S)(?i:[a-z\d]{4}|[a-z\d]{12})(?!\S)/'
(?<! \S ) # whitespace boundary
(?i: # case insensitive cluster group
[a-z\d]{4} # 4 alnum
| # or
[a-z\d]{12} # 12 alnum
)
(?! \S ) # whitespace boundary
我有这段文字:
SU4R
C45G
G3HD
61U14XE7AR23 914K16W471LV V6SQ5V16LG91 24YL4HW956C3 UZ26J12K615V T741MH4N739W 31ST445G726H 621EH6VW7Q6M 55N629WJ945P 56TX2W6LC949 44DS765CF739 XC262HV1JZ6V 26YD4N1Y71F7 S4M3F1XeDC0D
我想使用 preg_match
在该文本中查找特定类型的代码,因此我应该包含:
- 4 或 12 个字符
- 它应该返回所有元素
- 不区分大小写
- 字母和数字
我已经结束了:
preg_match("/^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z!@#$%]{4,12}/", $input_line, $output_array);
但是:
- 它只适用于 http://www.phpliveregex.com/p/byZ
- 它只找到前 4 个元素
- 为什么当我尝试使用此页面时 https://www.functions-online.com/preg_match.html 它只显示 1 个匹配项?
使用 preg_match_all(),类似这样的方法可能有效
http://www.phpliveregex.com/p/bz0
# '/(?<!\S)(?i:[a-z\d]{4}|[a-z\d]{12})(?!\S)/'
(?<! \S ) # whitespace boundary
(?i: # case insensitive cluster group
[a-z\d]{4} # 4 alnum
| # or
[a-z\d]{12} # 12 alnum
)
(?! \S ) # whitespace boundary