Hello
It's very strange, all java regex utilities makes the
same error when trying to match against a pattern and
extract a substring defined by a (...) pattern. All
regex utils group first the whole string and on the
secondary stage the () pattern. WHY??? Is it so hard to
keep on the basic doctrine of regex? See the sample:
#!/usr/bin/perl
my $test =
"[attribute-of:select=\"gidnumber@[parentAttribute:prefix]Admins]\"";
$test =~ /\[parentAttribute:(\w+)\]/;
print $1;
Matches exactly: prefix WHICH IT MUST BE!!!!
But on all java regex libraries the result (also on the
jregex demo applet) is:
0: <[parentAttribute:prefix]>
1: <prefix>
WHY WHY WHY????
When i write the pattern: \[parentAttribute:(\w+)\] I
KNOW ALREADY THAT THERE IS A WORD CALLED
"parentAttribute" I don't need to find it!!!!! But what
I'm interested in is the pattern result which is
(correctly on perl) "prefix".
Please, please, please, please correct this, because
this is not regex compatible. No unix based regex
library returns a such result!!
Roland Kaeser <roli@israel-jugendtag.ch>
Logged In: YES
user_id=367459
Sorry, I don't get the point of your message.
After the successful match in perl, the $1..$9 variables contain
the substring
corresponding to the parenthesised subexpressions (groups) of
the regex.
And the $& variable contains the (sub)string corresponding to the
whole regex.
And quite similarly, after the successful match in jregex, the
Matcher.group(N) N=1..9 returns the N-th group (the same string
that would be in the $1..$9 variable in perl). And the m.group(0)
returns (quite naturally IMHO) the same string as would be in the
$& in perl.
So what's so strange with it?
Anyway, couldn't you give me a sample of java code that you feel
so unpleasant of, and a variant that you would like more.