Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDk 1.5 regex utility

 
Nischal Tanna
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?....
 
Ajay Singh
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matcher.group gives you that
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
Nischal Tanna
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
\ 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
Marshal
Pie
Posts: 20880
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ajay Singh
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
correct
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic