Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ant regex?

 
slap shot
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a ${curDir} that looks like:

root/folder/projectname/temp/etc

and I want to use a regex to extract the projectname from that, what I currently have is:



only the output is \3 (or $3 if I try to use $) - what am I doing wrong?

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34396
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see two issues. First, you don't have any sets of parenthesis in your regular expression which means \1, \2 and \3 are not set to anything. Which means they print as string literals. You know the reg exp is matching something since it doesn't return Invalid.


This example prints "folder". "0" is a special match that means the whole match regardless of parens.

The second issue is that you aren't matching projectname. That's easy enough to solve. Just add to the regular expression. And add parens so it is the first match.



And this prints projectname.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34396
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, please see your PMs about an important administrative matter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic