newmrd has asked for the wisdom of the Perl Monks concerning the following question:

hello. can anybody help me converting code below from perl to java:

sub validate_and_fix_regex { my $regex = $_[0]; eval { qr/$regex/ }; if ($@) { $regex = rquote($regex); } return $regex; } sub rquote { my $string = $_[0] || return; $string =~ s/([^A-Za-z_0-9 "'\\])/\\$1/g; return $string; }

Replies are listed 'Best First'.
Re^2: From Perl to Java
by GrandFather (Saint) on Jun 28, 2015 at 06:26 UTC

    I suggest you try JavaMonks (or whatever the PerlMonks equivalent is for Java) or stack overflow. PerlMonks would help you convert Java to Perl but going the other way is rather off topic here.

    Perl is the programming world's equivalent of English
Re^2: From Perl to Java
by Anonymous Monk on Jun 28, 2015 at 13:12 UTC

    The piece of code qr/$regex/ depends on Perl's implementation of regular expressions and is therefore not directly translatable to Java. It may be translatable if $regex only contains a subset of Perl's regex features, but your post does not specify that.