Perl regular expression question

Posted by user368311 on Stack Overflow See other posts from Stack Overflow or by user368311
Published on 2010-06-16T14:02:29Z Indexed on 2010/06/16 14:12 UTC
Read the original article Hit count: 143

Filed under:
|

Suppose I have variables

$x1 = 'XX a b XX c d XX';
$x2 = 'XX a b XX c d XX e f XX';

I want a regular expression that will find each instance of letters between XX. I'm looking for a general solution, because I don't know how many XX's there are.

I tried using /XX(.*?)XX/g but this only matches "a b" for x1 and "a b", "e f" for x2 because once the first match is found, the engine has already read the second "XX".

Thanks for any help.

© Stack Overflow or respective owner

Related posts about regex

Related posts about perl