• 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

Regex problem

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi.. i am am having doubts in this program... can somebody please explain it to me... thanks..
code:





and thats why i did not understand the following code also...
code:

Thanks in advance...
[ January 30, 2008: Message edited by: sweety singh ]
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you been through the Java Tutorial about regular expressions?
Your 2nd pattern is obviously matching two or more digits, then starting when it finds something which is not a digit. So 335 matches on the 33, then the 5f doesn't match, then the 45 matches, then the 6, being a single digit, doesn't match.

Your first example uses args[1] as the String to be examined, and \d\w which is args[0] as the pattern/regular expression to test against. You can see at the bottom, you printed out \d\w as the pattern. Now \d\w means a digit followed by a "word character." You can find what "word characters" are from the link I quoted; look for "predefined character classes." So at position 4 (ie the 5th character) it found its 1st combination of a digit and a word character, 56. _7 doesn't count, but 7a is the next place where there is a digit followed by a "word character."
Read the link I quoted; it is nice and easy to understand.
 
sweety singh
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey thanks for that link.... but i could not find any pattern() in Matcher class... then how is it used...???
 
sweety singh
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey thanks i understood everything.. thank you...
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome . . . and well done.
 
reply
    Bookmark Topic Watch Topic
  • New Topic