File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Regex problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regex problem" Watch "Regex problem" New topic
Author

Regex problem

sweety singh
Ranch Hand

Joined: Dec 15, 2007
Posts: 49
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

Joined: Oct 13, 2005
Posts: 40052
    
  28
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

Joined: Dec 15, 2007
Posts: 49
hey thanks for that link.... but i could not find any pattern() in Matcher class... then how is it used...???
sweety singh
Ranch Hand

Joined: Dec 15, 2007
Posts: 49
hey thanks i understood everything.. thank you...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
You're welcome . . . and well done.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regex problem