firasdib / Regex101

This repository is currently only used for issue tracking for www.regex101.com
3.28k stars 199 forks source link

[Feature Request] Add Java regex handling #395

Closed PrincessRTFM closed 8 years ago

PrincessRTFM commented 9 years ago

Java strings require that backslashes used to escape metacharacters be themselves backslashes, such as \\(.+?\\) to match anything inside literal parens. I love the site, and use it for pretty much all of my regex testing, but it's annoying to have to escape my backslashes for java work when copying a tested regex into my project.

atorstling commented 9 years ago

A tip: if you use Intellij, pasting into a string literal will add the extra backslashes automatically.

PrincessRTFM commented 9 years ago

I use Eclipse, which can do the same, but I prefer to keep it off so I can paste string literals from other sources without mangling them.

chrisgotter commented 9 years ago

@Princess put your expression in an external text file, but I was actually about to post this exact same request. Is it possible to mod regex101?

OnlineCop commented 9 years ago

@chrisgotter We're working on a version 2 of the regex101 site right now. While we have not yet found a Javascript solution to emulate a Java regex, we may be able to figure out enough in the meantime to be able to produce a Java-compatible (or "compatible-enough to get by") code generator dump. It's still up in the air, but if you find any .NET, Java, or Ruby regex support which can port into Javascript (so the entire regex101 site can be used offline), by all means: post a github link and let us know.

chrisgotter commented 9 years ago

so the problem is the code generator not the ui?

PrincessRTFM commented 9 years ago

The main problem I'm having is that I have to double backslashes in Java strings, which I then pass to java.lang.regex.Pattern.compile(String[, int]) to make the regex. The biggest thing I'd like to see in "Java mode" is handling of that, so that \\[ represents a literal [ instead of the literal sequence \[ as it does now. That would prevent me needing to fiddle with the backslashes when copying from the site into my project, and (more importantly) when copying a regex from my project into the site for testing.

chrisgotter commented 9 years ago

paste it into the test area then put this \\\\ in the expression area and \ in the replace area. Then paste the output into the expression area.

firasdib commented 8 years ago

Best would be to create add a code sample for this that gets generated for you and fixes the backslashes.

nhahtdh commented 8 years ago

Dup of https://github.com/firasdib/Regex101/issues/245