public static Pattern convertPerlRegexToPattern(@Nonnull final String regex,@Nonnull final boolean faultTolerant){
  Check.notNull(regex,"regex");
  String pattern=regex.trim();
  final Matcher matcher=faultTolerant ? PERL_STYLE_TOLERANT.matcher(pattern) : PERL_STYLE.matcher(pattern);
  if (!matcher.matches()) {
    throw new IllegalArgumentException("The given regular expression '" + pattern + "' seems to be not in PERL style or has unsupported modifiers.");
  }
  pattern=pattern.substring(1);
  final int lastIndex=pattern.lastIndexOf('/');
  pattern=pattern.substring(0,lastIndex);
  final int flags=Flag.convertToBitmask(Flag.parse(matcher.group(1)));
  return Pattern.compile(pattern,flags);
}

public static Pattern convertPerlRegexToPattern ( @ Nonnull final String regex , @ Nonnull final boolean faultTolerant ) { Check . notNull ( regex , "regex" ) ; String pattern = regex . trim ( ) ; final Matcher matcher = faultTolerant ? PERL_STYLE_TOLERANT . matcher ( pattern ) : PERL_STYLE . matcher ( pattern ) ; if ( ! matcher . matches ( ) ) { throw new IllegalArgumentException ( "The given regular expression '" + pattern + "' seems to be not in PERL style or has unsupported modifiers." ) ; } pattern = pattern . substring ( 1 ) ; final int lastIndex = pattern . lastIndexOf ( '/' ) ; pattern = pattern . substring ( 0 , lastIndex ) ; final int flags = Flag . convertToBitmask ( Flag . parse ( matcher . group ( 1 ) ) ) ; return Pattern . compile ( pattern , flags ) ; }
converts a perl style regular expression into java style . < br > < br > the leading and ending slash and the modifiers will be removed .
