Regex101 icon indicating copy to clipboard operation
Regex101 copied to clipboard

Java flavor

Open moriak opened this issue 12 years ago • 23 comments

Any change of support for java?

Thanks for the great job.

moriak avatar Jun 25 '14 20:06 moriak

Still no success :(... I could host it on a server, but that would defeat the purpose.

firasdib avatar Jun 28 '14 17:06 firasdib

I just want to leave +1 for that feaure request as your online tool is the coolest tool for regular expressions I ever seen. I'd love to see the ability to construct regexps for java in it.

Grief avatar Aug 12 '14 10:08 Grief

+1 I do a lot of regexing in Java and this would be nice to have. Also, Ruby and .NET if possible :3

Donated hopefully <3

Supuhstar avatar Aug 13 '14 18:08 Supuhstar

+1 for idea. The differences between Java and PCRE is that several constructs are absent ((|, (?(condition)), presence of intersection classes and character set are presented differently (\p{Upper}, \P{Upper}), really. Is this possible by basing off Perl?

As mentioned by the official documentation:

The Pattern engine performs traditional NFA-based matching with ordered alternation as occurs in Perl 5. Perl constructs not supported by this class: [...] Constructs supported by this class but not by Perl: [...] Notable differences from Perl: [...]

Also, idea for code generation:

Pattern re = Pattern.compile( /* Pattern here with literals escaped */);
String str = /* String here */;
Matcher obj = re.matcher(str);
while (obj.find())
    System.out.println(obj.group());

Unihedro avatar Sep 21 '14 06:09 Unihedro

@Vincentyification I could create a syntax parser for Java and use the PCRE engine underneath. It's probably not going to work identically to Java, but pretty damn close and it will check the syntax for people.

firasdib avatar Sep 21 '14 09:09 firasdib

@firasdib That's a great idea, and possibly close to where I was originally going. Since the Java Pattern syntax doesn't change frequently (In fact, since it was established on Java 5 it never changed), any maintainable implementation would work for this case. I thought of this while searching for a Java library which could parse PCRE, but got sidetracked seeing http://regex101.com having an exclusive bullet point documented by Wikipedia under "Links" section. I thought since Java syntax is based on Perl, a short regex could be used to check for invalid syntaxes that wouldn't apply in Java, and converting Java-style character classes to Perl. [[:hex:]] -> \p{XDigit}, et cetera. As for the class intersections, I think you could get away by converting them to positive / negative lookaheads and faking the relevant sections in the "regex debugger". As for the related ticket about Ruby regex support, there's a bigger issue in the syntax similarities, so I'm only suggesting a parser for Java input for now.

Unihedro avatar Sep 21 '14 09:09 Unihedro

+1

FabianFrank avatar Sep 25 '14 20:09 FabianFrank

+1. I missed out on this post and created a new one. Please disregard that.

Thanks.

Khanna111 avatar Dec 05 '14 20:12 Khanna111

@Vincentyification: There are lots of f*ck up things in the reference implementation (Oracle and OpenJDK) of Java regex that wouldn't present in PCRE. For example: negation of negation of character class, definition of \b not based on \w, capturing group manage to capture stuffs in negative look-around, incorrect retention of captured content, integer overflow in length calculation to limit look-behind, high stack usage leading to StackOverflowError for greedy repetition, ... (CANON_EQ not mentioned here, since it is a buggy and unusable feature). It will cause confusion for user if you use PCRE implementation here.

nhahtdh avatar Jan 13 '15 08:01 nhahtdh

@nhahtdh +1 Great points!

Supuhstar avatar Jan 15 '15 16:01 Supuhstar

+1 for explicit Java support

asmaier avatar Mar 18 '15 13:03 asmaier

Support for intersections in Java would be great: http://www.regular-expressions.info/charclassintersect.html (Just made a small donation re this feature)

niccottrell avatar Mar 22 '15 16:03 niccottrell

+1 please add this

Claudweb avatar Apr 07 '15 08:04 Claudweb

:+1:

mrslain avatar Mar 20 '16 18:03 mrslain

The new release will feature a code generator for Java which might help some, alteast with those pesky backslashes. The PCRE engine is still as close as you're going to get, which is likely going to cover it for most of your cases. But so far I have not been able to get the actual engine running. Sorry!

firasdib avatar Aug 22 '16 21:08 firasdib

me too

xenoterracide avatar Feb 17 '21 17:02 xenoterracide

Hi everybody! I just managed to compile the Java regex engine to javascript by taking the engine from the openjdk (java.lang.Pattern, java.lang.Matcher, etc.) and running TeaVM on it. I've sent my work to @firasdib, so hopefully he'll get it working soon :pray: :smile:

It's currently based on java 8, does anybody know if there is any relevant changes made to the engine since then?

simonlindberg avatar Mar 04 '21 22:03 simonlindberg

@simonlindberg As far as I know, yes there were some changes made to the regexp engine after Java 8 : https://bugs.openjdk.java.net/issues?jql=project%20%3D%20JDK%20AND%20status%20in%20(Resolved%2C%20Closed)%20AND%20resolution%20%3D%20Fixed%20AND%20component%20%3D%20core-libs%20AND%20Subcomponent%20in%20(java.util.regex%2C%20java.util.regex%2C%20java.util.regex%2C%20java.util.regex)

OlivierJaquemet avatar Mar 05 '21 08:03 OlivierJaquemet

@OlivierJaquemet Looked at a few and most of them seems to be performance related or regressions i later version. I did find one that might be related, https://bugs.openjdk.java.net/browse/JDK-6609854 , might be more like it. But since Java 8 still is the most popular version I think in that case there should be multiple java flavors available (all the LTSs perhaps?). As long as the version is clearly stated I think only Java 8 is a good start! :)

simonlindberg avatar Mar 05 '21 09:03 simonlindberg

Thanks to the work by @simonlindberg, you can expect regex101 to support java shortly! Keep a close eye on the website the coming days...

firasdib avatar Mar 10 '21 12:03 firasdib