This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes ant regex? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "ant regex?" Watch "ant regex?" New topic
Author

ant regex?

slap shot
Greenhorn

Joined: Feb 21, 2013
Posts: 1
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30361
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30361
    
150

Also, please see your PMs about an important administrative matter.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ant regex?