The named groups functionallity is exactly what I've been looking for!
Is there any way of retrieving all the groups, or all the named groups that a match contains? I just have 3 named groups that I'm capturing, and the rest will enter in a category called "other". I can work around this by comparing the strings with the ones I captured. However, if one of the groups contains the same text I'm going to miss it.
Thanks for the great work!
PS.: do you guys have any perfomance comparisons against javax.regex?
[]s Gustavo
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There is no way to get group names without prior knowing them.
As a temporary workaround you can slightly change the source: add appropriate accessor methods for the Pattern.namedGroupMap hashtable, which contains the name(String)->id(Integer) pairs.
Concerning performance.
The jregex is slightly slower with short target strings (<80-100 chars) and faster otherwise.
You can make it even better by reusing the Matcher objects (see docs on Matcher.setTarget()).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Regarding the performance, I've noticed that, but I'm parsing large (2-16KB) multi-line strings, and it's quite faster than Sun's. And I like your sintax for named groups better, even though it's not perl standard.
I think I'll wait before changing the code, I'm afraid to break compatibility.
Again, thanks for the tips.
[]s Gustavo
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Folks!
The named groups functionallity is exactly what I've been looking for!
Is there any way of retrieving all the groups, or all the named groups that a match contains? I just have 3 named groups that I'm capturing, and the rest will enter in a category called "other". I can work around this by comparing the strings with the ones I captured. However, if one of the groups contains the same text I'm going to miss it.
Thanks for the great work!
PS.: do you guys have any perfomance comparisons against javax.regex?
[]s Gustavo
To retrieve all the groups use the Matcher.groups() or the
for(int i=0;i<Patterm.groupCount();i++) String group=Matcher.group(i);
There is no way to get group names without prior knowing them.
As a temporary workaround you can slightly change the source: add appropriate accessor methods for the Pattern.namedGroupMap hashtable, which contains the name(String)->id(Integer) pairs.
Concerning performance.
The jregex is slightly slower with short target strings (<80-100 chars) and faster otherwise.
You can make it even better by reusing the Matcher objects (see docs on Matcher.setTarget()).
Thanks!
Regarding the performance, I've noticed that, but I'm parsing large (2-16KB) multi-line strings, and it's quite faster than Sun's. And I like your sintax for named groups better, even though it's not perl standard.
I think I'll wait before changing the code, I'm afraid to break compatibility.
Again, thanks for the tips.
[]s Gustavo