• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regular expression doubt

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Burke can you explain why this (?=(\d+))\w+\1 not match "123x12" but
match "56x56" in "456x56" ??
 
Greenhorn
Posts: 16
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Giovanni,

"(?=(\\d+))\\w+\\1"

(?=(\\d+)) - it will match and construct an Number set
\\w+ - Matches one or more characters
\\1 - Exactly matches the first Group, means (?=(\\d+))

When we pass a 123x12 - first group matches three number sets, they are 123, 23 and 3
So the same set should appear after the character.
We have 12 after the character x, so 12 is not matched with any of the number set returned by group 1.
this is the reason why it is not matched.

We'll take the second (+ve) example:

When we pass a 456x56 - first group matches three number sets, they are 456, 56 and 6
We have 56 after the character x, so it is matched.

Hope what i explained is understandable.


Thanks,
Rajasekar.
 
Giovanni Lima
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rajasekar! It's clear now for me how it really works
 
reply
    Bookmark Topic Watch Topic
  • New Topic