Does anyone have an example of how to use regexsplit
Brent Putman
putmanb at georgetown.edu
Fri Sep 28 15:36:12 EDT 2012
On 9/27/12 6:42 PM, Tom Poage wrote:
> Is the regex like (or does it invoke) Java's split() method? If so, the regex would be composed to match the separator, i.e. "/".
>
> Tom.
>
No, it doesn't use split, it uses java.util.regex.Matcher and
java.util.regex.Pattern essentially like this:
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(target);
if(matcher.matches()) {
return matcher.group(1);
}
Based on some quick testing, the following regex patterns do work on the
OP's data:
^(Student|faculty|Faculty|Staff).*
^(\\w+).*
Without the wildcard pattern on the end (.*) it doesn't match
(matcher.matches() returns false).
This is different than Perl 5's behavior, which does match:
perl -le '($result) = "Faculty/pt" =~ /(Student|faculty|Faculty|Staff)/;
print $result;'
produces "Faculty".
Javadoc for Pattern notes that " The Pattern engine performs traditional
NFA-based matching with ordered alternation as occurs in Perl 5."
I don't immediately see any reason in the docs for the different
behavior between the 2. But that's what it's doing apparently.
--Brent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://shibboleth.net/pipermail/users/attachments/20120928/89af310e/attachment.html
More information about the users
mailing list