News for hackers. Stuff that matters.
Re:RegExr by zmix on Monday August 05, 2019 @05:53PM (#20619451)
These: regex101.com and regexper.com !

Regexper will render your regular expression as a friggin' railroad diagram!! It's extremely handy when debugging your regex or to understand those super complex, multiline regexes, that someone has posted to Stack Overflow.

Both regular-expressions.info and rexegg.com are incredibly good explanations of Regular Expressions.

regular-expressions.info is even available as a PDF e-book against a tip of your choice.

Re:RegExr by mgaw on Monday August 05, 2019 @03:52PM (#20618132)
Here is one for Ruby: https://rubular.com/
Re:RegExr by bklaasen on Monday August 05, 2019 @06:41PM (#20619942)
Time for a shout-out to Lea Verou's terrific fifty-minute tutorial "Regexplained" and accompanying regex playground:

https://youtu.be/EkluES9Rvak

https://regexplained.com/

Re:RegExr by lpellis on Monday August 05, 2019 @03:12PM (#20617553)
And for python this one is nice: https://pythex.org/
Re:RegExr by ehsankia on Tuesday August 06, 2019 @02:42AM (#20622769)
Regex101 let's you switch mode, and has a python regex one.
Re:RegExr by fb03 on Tuesday August 06, 2019 @09:43AM (#20625067)
pythex works ok but it's UI/UX is worse than regex101 (which as a friend state, has pythonre capabilities as well.

try regex101 and you won't look back.

Re:RegExr by jonny_eh on Monday August 05, 2019 @03:55PM (#20618161)
Thanks for the list, but are they all the same? Why go to one over the other?
Re:RegExr by ehsankia on Tuesday August 06, 2019 @02:43AM (#20622772)
It makes me wonder, is there something about Regex that makes people want to create so many tools for it, even after so many other ones already exist?
Re:RegExr by DominoTree on Monday August 05, 2019 @06:33PM (#20619860)
Some support other varieties of RegEx, and some have interesting features or different interfaces
Re:RegExr by msravi on Tuesday August 06, 2019 @12:44AM (#20622204)
Not sure if it's completely comprehensive, but the clearest tutorial/reference of regex's that I've used is in the book "The AWK Programming Language" by Aho, Kernighan, Weinberger.

https://ia902309.us.archive.org/25/items/pdfy-MgN0H1joIoDVoI...

Re:RegExr by sk5t on Tuesday August 06, 2019 @01:47AM (#20622492)
That is a nice introduction indeed. Afterwards, to get a taste for more complex matching, maybe the Perl / PCRE docs.

https://perldoc.perl.org/perlre.html

Re:RegExr by asicsp on Tuesday August 06, 2019 @01:01AM (#20622281)
I especially like debuggex for debugging/teaching purposes, here's an example: https://www.debuggex.com/r/SMLRfiyt0Ag2hXu5
Re:RegExr by drewroberts on Tuesday August 06, 2019 @02:20AM (#20622656)
Thank you for posting these links. I'm lost whenever I attempt something with Regex.
Re:RegExr by eridius on Monday August 05, 2019 @04:51PM (#20618784)
Are there any online regex testers for ICU regexes?
Re:RegExr by jasode on Monday August 05, 2019 @12:27PM (#20615428)
I prefer regex101.com because that site assigns different colors to different capture groupings. I made a previous comment on this and why it's helpful: https://news.ycombinator.com/item?id=9581692

(For some reason RegExr.com is submitted to HN much more often than regex101.com. Is there a compelling advantage to RegExr that I've overlooked?)

Re:RegExr by leovander on Monday August 05, 2019 @02:17PM (#20616708)
Although it's overkill when I could have a reference sheet on my computer or on the wall, but I always remember that regexr has its cheat sheet on the side that I can easily get to. I use their cheat sheet more than the actual editor on their page.

It looks like regex101 has it as well, but the regexr one is straight to the point (at least for me). https://i.imgur.com/Hg9jGOa.png

Re:RegExr by United857 on Monday August 05, 2019 @05:29PM (#20619205)
regexr is open source, unlike regex101.
Re:RegExr by Toury2d on Monday August 05, 2019 @06:14PM (#20619672)
That doesn't make it better.
Re:RegExr by wodenokoto on Monday August 05, 2019 @01:16PM (#20615972)
I prefer regex101 too. I think it has fewer features, but it has the right features and is so easy to approach.

I’m a big fan.

Re:RegExr by goerz on Monday August 05, 2019 @01:48PM (#20616356)
The problem I have with all of these regex websites and tools is that they usually only use the regex dialect of whatever language they’re written in. Or at best, a very incomplete list of dialects. Subtle differences between dialects matter a lot. Personally, I would need at least Perl, Python, GNU utils (with and without -E), BSD utils (or whatever comes with macOS, again with and without-E), and vim with the various settings for “magic”. Ideally, they would also be able to convert between all these dialects.
Re:RegExr by LameRubberDucky on Monday August 05, 2019 @03:22PM (#20617697)
If you were on Windows, you could try RegexBuddy. It supports regex dialects for: .NET, Boost (C++), Delphi, Groovy, Oracle Database, PowerShell, R, std::regex, VB6, wxWidgets, C#, MySQL, PHP, PostgreSQL, VBScript, Java, Perl, PCRE, JavaScript, Python, Ruby, Tcl ARE, POSIX BRE, POSIX ERE, GNU BRE, GNU ERE, XML Schema, and XPath. It will even generate code snippets for you based on the regex you create with the tool. It can also convert between these dialects and lets you know if features in the target dialect are not available.

I am not associated with this company in any way, just a long time user.

Re:RegExr by goerz on Monday August 05, 2019 @04:58PM (#20618867)
That does look impressive! I'm tempted to check how well this runs in Wine (since I'm not a Windows user)
Re:RegExr by las_balas_tres on Tuesday August 06, 2019 @03:01AM (#20622845)
RegexBuddy is a fantastic piece of software. It also runs fine under Wine.
Re:RegExr by jonny_eh on Monday August 05, 2019 @03:56PM (#20618176)
https://regex101.com/ supports 4 dialects. Certainly not exhaustive, but very handy none-the-less.
Re:RegExr by 1f60c on Monday August 05, 2019 @02:37PM (#20617007)
Sounds like a fun side project :D
Re:RegExr by dang on Monday August 05, 2019 @02:46PM (#20617150)
Re:RegExr by tabtab on Monday August 05, 2019 @02:22PM (#20616776)
I find RegEx's a bit cryptic. Sure, with enough practice one can read them, but I'd like an alternative that can easily break out chunks as named units. One can then reference the named units to compose new named units. Divide-and-Conquer.

I'd like to see experiments in alternatives that provide this. It could help do for RegEx's what SQL's WITH statement did for long SQL statements.

Backus–Naur Form could act as a starting point, but it needs some syntactic adjustments to make it more compact and practical, in my opinion. Partial example:

     Side = VarFunc + Segment*;
     Segment = 
         ":" + Varfunc
      | (":" + VarFunc)[0..1] + "{" + "}"
      | (":" + Varfunc)[0..1] + "{" + Base + (";" + Base)* + "}";
     Letter = ('a'..'z'|'A'..'Z');
     ForbiddenChar = $anyChr("/?#%");
     /*
     Legend:
       [x..y] = quantity of repeats (substitute letters with integers)
       [0..n] = zero, one, or multiple
       * = shorthand for [0..n]
       | = "or"
       + = concatenation, ignores white-space
       ++ = concatenation, excludes white space
       +w+ = concatenation, must have white-space between
       'x'..'y' = character falls within range
       $x() = special function or constant, where "x" is a name.
     */
Re:RegExr by btilly on Monday August 05, 2019 @03:23PM (#20617730)
It sounds like you would like https://en.wikipedia.org/wiki/SNOBOL.

Though if you had to do enough work with text, my bet is that you'd eventually figure out why regexes won. They are simple, straightforward, and just enough to tackle the occasional matching problem on your way to doing something else.

Re:RegExr by jnbiche on Monday August 05, 2019 @07:23PM (#20620329)
Have you tried Parsing Expression Grammars (PEGs)? Most implementations allow use to name arbitrary sub-parsers, often using the programming language's native variables.

See for example Peg.js, LPEG (lua), etc. However, PEGs don't natively permit left recursion (note: some PEG implementations do add that on). If that's a problem, Earley parsers are a nice alternative.

Example of a calculator using Peg.js:

  start
    = additive

  additive
    = left:multiplicative "+" right:additive { return left + right; }
    / multiplicative

  multiplicative
    = left:primary "*" right:multiplicative { return left * right; }
    / primary

  primary
    = integer
    / "(" additive:additive ")" { return additive; }

  integer "integer"
    = digits:[0-9]+ { return parseInt(digits.join(""), 10); }
Re:RegExr by maddyboo on Monday August 05, 2019 @05:45PM (#20619380)
I wrote a very crude library like this in VimL to make writing syntax plugins a bit easier: https://github.com/b0o/builder.vim

You can see it in use here: https://github.com/b0o/quicktemplate.vim/blob/master/syntax/...

Re:RegExr by arnarbi on Monday August 05, 2019 @03:23PM (#20617731)
PCRE has the DEFINE keyword. Here's an example: https://regex101.com/library/gJ7pU0

(not to be confused with named capture groups)

Re:RegExr by tosh on Monday August 05, 2019 @02:25PM (#20616817)
There is a concept of named capturing groups:

https://www.regular-expressions.info/named.html

Re:RegExr by zmix on Monday August 05, 2019 @05:56PM (#20619487)
https://regexper.com will render your regex as railroad diagram. Maybe a help...
Re:RegExr by earenndil on Monday August 05, 2019 @03:03PM (#20617431)
Look at perl6 grammars.
Re:RegExr by tabtab on Monday August 05, 2019 @03:09PM (#20617522)
It looks extensive, but perhaps may be overkill for a common regex alternative. Thanks for the tip, though. A standard or semi-standard would have to start simple.
Re:RegExr by janpot on Monday August 05, 2019 @12:22PM (#20615378)
I usually prefer https://regexper.com/. Especially when trying to make sense of regexes I come across in code I didn't write.
Re:RegExr by mattupstate on Monday August 05, 2019 @12:53PM (#20615683)
I've been using this website for years. It's been so long now that I can't even remember when Grant Skinner, the former Flash/ActionScript guru, released it. Nice to see it shared here.
Re:RegExr by jedberg on Monday August 05, 2019 @02:47PM (#20617179)
Why is there a sudden explosion of posts about regex in the last few days? Did something newsworthy happen that I missed, or is it more of a "I saw the post last week and then found this cool related thing" bandwagon effect?
Re:RegExr by LeonB on Tuesday August 06, 2019 @02:07AM (#20622598)
I thinks it’s the latter.

If there is a major news item involving regular expressions, we’re all ready to pounce, ala: https://xkcd.com/208/

Re:RegExr by ollerac on Monday August 05, 2019 @01:58PM (#20616483)
This is nice, but my go to tool is: https://www.debuggex.com/

Not only does it tell you what everything means, but it visually displays it in a way that just makes sense.

Re:RegExr by zamadatix on Monday August 05, 2019 @07:57PM (#20620602)
This is always the one I forget about and have a hard time finding. It's not really great for editing but it's probably the best display I've seen in regards to debugging large regex.
Re:RegExr by proactivesvcs on Monday August 05, 2019 @05:40PM (#20619339)
I can highly recommend the following tool: Mastering Regular Expressions by Jeffrey Friedl http://shop.oreilly.com/product/9780596528126.do

I found the pacing to be excellent, with complimentary exercises and that it was educational as both a cheatsheet and a coherent text. Learned a lot from it, despite being experienced from the outset.

Re:RegExr by ekzy on Monday August 05, 2019 @01:10PM (#20615884)
For ruby regex, I use https://rubular.com/

Actually I use it for all platforms, and it works most of the time. If I notice that something is odd because the regex engine is different, then I'll use something else. But I really value Rubular's UI simplicity.

Re:RegExr by err4nt on Monday August 05, 2019 @12:18PM (#20615322)
Beautiful! I tried it with a particularly nasty regex from a codebase I had and it did a fantastic job explaining what it would target. It's similar to regex101.com in a lot of ways, but the UI might be a little more easy to read and understand.
Re:RegExr by KenanSulayman on Monday August 05, 2019 @03:08PM (#20617502)
Something I can recommend to both experienced and "new developers" alike is https://regexper.com.

It generates clear graphs from regular expressions making immediately clear what they do.

Re:RegExr by pcr910303 on Monday August 05, 2019 @12:31PM (#20615472)
I love this tool. I have customized Emacs keybindings that open RegExr in a xwidget-webkit instance, type in regexes, and exit RegExr with the regex inserted at the cursor.

Great for reading monstrous regexes or sharpening my regex skills.

Re:RegExr by yboris on Monday August 05, 2019 @12:18PM (#20615316)
This is always my go-to tool when I'm trying out RegEx!
Re:RegExr by rudiv on Monday August 05, 2019 @12:22PM (#20615370)
Same, I'm a big fan.
Re:RegExr by throwaway5389 on Monday August 05, 2019 @10:32PM (#20621570)
One thing that's always perplexed me is the variants of regex and their differences - is there any write up that defines the majority of them?
Re:RegExr by x4nt on Monday August 05, 2019 @01:31PM (#20616159)
Been using RegExr for years!
Re:RegExr by tabs_masterrace on Monday August 05, 2019 @01:59PM (#20616492)
Me too! I have to admit I'm really bad at it and can never remember how the heck regular expressions work, but whenever I have to come up with something I just fiddle around in RegExr until it works. Documentation in the sidebar is super handy too.
Re:RegExr by boomskats on Monday August 05, 2019 @03:22PM (#20617704)
regex101.com lets me have client-side validation without requiring a network connection, so it's way more useful to me than regexr (although the regexr UI is nice and I like their github repo).
Re:RegExr by svnpenn on Monday August 05, 2019 @01:30PM (#20616140)
doesnt support POSIX character classes.

this should be preferred over `a-z` as the latter relies on users locale.