regex - Capturing repeated word sequence -
in perl, match text pattern a11a, g22g, x33x below regex works fine
([a-z])(\d)\g2\g1 now want match repeating groups similar above having space in between words like
abcd 101 abcd 101 ( catch entire string in single regex pattern in 1 single line text or paragraph )
how this...i tried below pattern wont work
([a-za-z]*\s)([0-9]*\s)\g1\g2 #logic : words followed space in 1 group , #numbers followed space in 2nd group also, please explain why above regex fails capture desired text pattern!!!
edit
one more complication :
assume pattern
[words][space][numbers][space][words][space][numbers] #assume [numbers] , [word] same ....so in last [numbers] case, [space] doesn't follow, how filter then...because regex group capture like:
([0-9]*\s) fails capture last part if repeated, and
([0-9]*) fail capture mid-part if repeated!! ?? regex 101
your problem regex expects space @ end, because have included space in captures.
try instead:
([a-za-z]+)\s([0-9]+)\s\g1\s\g2
Comments
Post a Comment