Does anyone have an example of how to use regexsplit

Leonard Kroll Leonard.Kroll at umb.edu
Fri Sep 28 15:39:34 EDT 2012


Thank you all for your help.
I got it working by using regex: [a-zA-Z]*.*

This was a bit different behavior than I was used (perl).

~lennyK

From: users-bounces at shibboleth.net [mailto:users-bounces at shibboleth.net] On Behalf Of Brent Putman
Sent: Friday, September 28, 2012 3:36 PM
To: users at shibboleth.net
Subject: Re: Does anyone have an example of how to use regexsplit



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+).*<file:///\\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/d2d6e427/attachment.html 


More information about the users mailing list