You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is more of a reminder as Flavio is already aware that Perl and Java behave differently when dealing with /[a b]/x. In Perl that regexp is equivalent to /[a b]/ while in Java it is equivalent to /[ab]/.
This tends to break even more when we use /[ ]/x to refer to /\ /.
Sample file:
my$input = 'a b c';
my$regexp_string = qq{a [ ] b \\s c};
print"Trying '$input' =~ /$regexp_string/x\n";
$input =~ /$regexp_string/xordie"Failed regexp string: '$input' =~ /$regexp_string/x";
print"Ok '$input' =~ /$regexp_string/x\n";
Perl output:
Trying 'a b c' =~ /a [ ] b \s c/x
Ok 'a b c' =~ /a [ ] b \s c/x
Java output:
Trying 'a b c' =~ /a [ ] b \s c/x
Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character class near index 11
a [ ] b \s c
^
at java.util.regex.Pattern.error(Pattern.java:1955)
at java.util.regex.Pattern.clazz(Pattern.java:2548)
at java.util.regex.Pattern.sequence(Pattern.java:2063)
at java.util.regex.Pattern.expr(Pattern.java:1996)
at java.util.regex.Pattern.compile(Pattern.java:1696)
at java.util.regex.Pattern.<init>(Pattern.java:1351)
at java.util.regex.Pattern.compile(Pattern.java:1054)
at PlRegex.<init>(Main.java:1209)
at Main.main(Main.java:3498)
The text was updated successfully, but these errors were encountered:
This is more of a reminder as Flavio is already aware that Perl and Java behave differently when dealing with
/[a b]/x
. In Perl that regexp is equivalent to/[a b]/
while in Java it is equivalent to/[ab]/
.This tends to break even more when we use
/[ ]/x
to refer to/\ /
.Sample file:
Perl output:
Java output:
The text was updated successfully, but these errors were encountered: