Problem on Regular Expression (PREG) for preg_match
Possible cases: (pls ignore quote characte开发者_C百科r'')
'#APPLE '
' PINEAPPLE'
' *LEMON '
' ORANGE… '
' * STRAWBERRY '
' PEAR '
' # BANANA'
' %KIWI '
I've try %.[a-zA-Z]{2,}+%
seem cannot solve this problem, any expertise can help to grep be
'APPLE'
'PINEAPPLE'
'LEMON'
'ORANGE'
'STRAWBERRY'
'PEAR'
'BANANA'
'KIWI'
Instead of preg_match, use preg_match_all instead.
$pattern_test = "%[a-zA-Z]{2,}+%";
preg_match_all($pattern_test,$string,$matches);
print "<pre>"; var_dump($matches); print "</pre>";
Use a website test tool for Perl regular expressions, e.g.
http://www.spaweditor.com/scripts/regex/index.php
Enter your expression:
%[a-zA-Z]{2,}+%
Enter your data:
'#APPLE ' ' PINEAPPLE' ' *LEMON ' ' ORANGE… ' ' * STRAWBERRY ' ' PEAR ' ' # BANANA' ' %KIWI '
And run the expression:
Array
(
[0] => Array
(
[0] => APPLE
[1] => PINEAPPLE
[2] => LEMON
[3] => ORANGE
[4] => STRAWBERRY
[5] => PEAR
[6] => BANANA
[7] => KIWI
)
)
That uses the following function:
preg_match_all('%[a-zA-Z]{2,}+% ', '{{your data}}', $arr, PREG_PATTERN_ORDER);
精彩评论