| 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: 32827
|
|
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: 32827
|
|
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 ]
|
 |
 |
|
|
subject: regular expression pattern
|
|
|