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 

regex101 demo

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

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -