File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regex problem

 
sweety singh
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey thanks i understood everything.. thank you...
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome . . . and well done.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic