wood burning stoves 2.0*
The moose likes Java in General and the fly likes JDk 1.5 regex utility Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "JDk 1.5 regex utility" Watch "JDk 1.5 regex utility" New topic
Author

JDk 1.5 regex utility

Nischal Tanna
Ranch Hand

Joined: Aug 19, 2003
Posts: 182
Hi Friends
I am currently doing the migration from jdk1.3 to jdk 1.5...So also need to migrate from apache regex to java.util.regex.
Both the packages have almost all the utility methods common functionally...however in apache regex, there is a method called getParen(int) which gives the value of the specified sub expression after the match is successful. Is there any such method or way of achieving the same using jdk 1.5 regex ?....


Thnx
Ajay Singh
Ranch Hand

Joined: Dec 13, 2006
Posts: 182
Matcher.group gives you that
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not an advanced question. Moving...


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Nischal Tanna
Ranch Hand

Joined: Aug 19, 2003
Posts: 182
Thanks Ajay

One more query:

I was searching the jdk 1.5 docs to see how i can tell the expression that it may encounter a meta character like *, [, etc.

I have an expression in apache regex codebase as "(((\\d+)\\d*)\\d*)D"... I guess the single "\" represents a meta character....may be a sample data for this expression can be "*20*20*2006"...pls correct me if i am wrong...

My query is in jdk 1.5 how can i write the above expression...the only problem i am facing is the represantation of the meta character in jdk1.5...

Any1 knows abt this?
Ajay Singh
Ranch Hand

Joined: Dec 13, 2006
Posts: 182
\ is escape character.
the regex to match "*20*20*2006" would be \\*\\d+\\*\\d+\\*\\d+.
more: http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

To disable a regex qualifier (such as *, +, ., or [), you have to escape it with a "\". And since the "\" hava special meaning to a java string, you have to escape the "\" too.

For example, to match "*20*20*2006", the regex should be "\\*20\\*20\\*2006".

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ajay Singh
Ranch Hand

Joined: Dec 13, 2006
Posts: 182
correct
 
wood burning stoves
 
subject: JDk 1.5 regex utility
 
Similar Threads
best free DB with Swing?
split and regexps
Split String seperated by "."
Regex Issue
Unable to compile class for JSP: