Reputation: 35
Possible cases: (pls ignore quote character'')
'#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'
Upvotes: 0
Views: 83
Reputation: 12866
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);
Upvotes: 1
Reputation: 7583
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>";
Upvotes: 2