in reply to PCRE: Repeating Subpattens After Intervening Characters
merlyn's on-target comment aside, I'd normally do that by assigning the repeated pattern to a variable and interpolating that into the regex pattern.
# original: my $pat = "\d\s+foo"; # fixed: my $pat = "\\d\\s+foo"; my $regex = qr/$pat[^\r\n]*$pat/;
Not sure about PCRE, but whatever programming language you use, I suspect you can construct a string using variables similarly to build up to your pattern.
Update: Doh! Thanks, ikegami. I was trying to show the subpattern with strings for the cross-language analogy and slipped up.
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: PCRE: Repeating Subpattens After Intervening Characters
by ikegami (Patriarch) on Sep 14, 2005 at 22:18 UTC | |
|
Re^2: PCRE: Repeating Subpattens After Intervening Characters
by schnarff (Acolyte) on Sep 14, 2005 at 22:09 UTC | |
by ikegami (Patriarch) on Sep 14, 2005 at 22:22 UTC |