Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perlito java regexps whitespace mismatch with /[a b]/x #40

Closed
potyl opened this issue Jan 19, 2016 · 0 comments
Closed

Perlito java regexps whitespace mismatch with /[a b]/x #40

potyl opened this issue Jan 19, 2016 · 0 comments

Comments

@potyl
Copy link
Collaborator

potyl commented Jan 19, 2016

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/x or die "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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant