aspose file tools*
The moose likes Java in General and the fly likes regular expression pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "regular expression pattern" Watch "regular expression pattern" New topic
Author

regular expression pattern

Ranadhir Nag
Ranch Hand

Joined: Mar 09, 2006
Posts: 138
We have a shell script which sets various environment variables.
We are interested in one line in that file as follows:

GATEWAY=devsol1:5340;export GATEWAY

Here the ':5340' may or may not be present.

We are trying out a pattern :
Pattern.compile("^(GATEWAY=)(.*)(( ([0-9]+)?)(;.*)($)")
Although this seems to work fine, we needed to confirm whether this is indeed the correct way to capture our used-case.

When we specify the grouping as '(( ([0-9]+)?)' does the '?' apply to just '([0-9]+)' or '( ([0-9]+)' as a group?
[ June 02, 2008: Message edited by: Ranadhir Nag ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36598
    
  16
I think the latter, but it is difficult to read your post. Please click the pencil-and-paper "edit" icon and tick "disable smilies" at the lower left to get rid of the extraneous
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36598
    
  16
On a closer look, I think I was mistaken.

In ([0-9]+)? the ? applies to ([0-9]+).
Ranadhir Nag
Ranch Hand

Joined: Mar 09, 2006
Posts: 138
How then we state that '( ([0-9]+)' may or may not be present as a group ; and yet refer to both '( ' and '([0-9]+)' separately as 'group' through matcher?
An exammple output from the matcher would be as follows:
group 2 - devsol1
group 3 - :
group 4 - 5340
[ June 02, 2008: Message edited by: Ranadhir Nag ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regular expression pattern
 
Similar Threads
Regular Expression Question
java regex pattern
Why doesn't this match?
IP address regular expression
Read log file from date to date as one object