3 ms·
It is actually true for PCRE (PHP), Python, and and a bit for non-global Javascript regex. For global matches in JS it is, I dare to say, incredibly difficult,
by myfonj 11y ago
It is actually true for PCRE (PHP), Python, and and a bit for non-global Javascript regex. For global matches in JS it is, I dare to say, incredibly difficult, if not impossible. I haven't seen visualised submatches in JS anywhere. I'd be happy to be mistaken and corrected.
So go on, try it right away :] I think it might be possible to get it done with breaking original regexp into group tree and look what each part did on concrete match from global search using non-global match on local instances. You'd need own regex parser and watch out for deep nesting.
- logicallee 11y agoThen I think I misunderstood what jasode was asking. Specifically, the example (our link) already names groups if you hover over matching text (group #1, etc) - I thought they were just asking for the highlight color to correspond to the group # listed.
- jasode 11y agoThanks for mentioning the tooltip popups. I didn't realize RegExr used mouseover/hover events on the matching text since the other regex sites don't do that. (It seems like non-obvious UX/UI but I now notice that the bottom left corner does say "Roll over a match or expression for details" -- but who reads the instructions?!?! Nobody's got time fo 'dat.) Nevertheless, I prefer explicit color-coding highlighting the boundaries instead tooltips displaying the offset numbers.
- logicallee 11y agoyes, I only knew about the hovering because of the instructions, which I did read. FWIW, my reaction was it would probably be better if they were all visible at once, who has time to hover over stuff. anyway since they have the logic to already know what to put in the tooltip, making that number determine a color seems like it would be simple, almost as simple as appending it to the tooltip. (if indeed that's all that's missing.) email the author your suggestion :)
- Roodgorf 11y agoInteresting, somehow I just instinctively moused over the text when I first visited the page. Another example of the subjectivity of UX and need for UI to be explicit and versatile I guess.
- tsergiu 11y agoAuthor of Debuggex here. Debuggex actually has the /g flag always enabled (the example above happened to have just one match), and it works for JS [1]. Groups for JS are indeed quite tricky. However, they come for free if you implement state visualization, since you need your own regex engine to do that (and can use said engine for the position of groups). [1]: https://www.debuggex.com/r/wSCkdE0_MNrysz4x https://www.debuggex.com/r/wSCkdE0_MNrysz4x
- jasode 11y agoIn my examples, it looks like debuggex didn't match "\s" to newline in "...Z\n0..." but regex101.com does. I don't know if that behavior for not matching newline matching is desirable since "\s" is supposed to include [ \t\r\n\f]. (See [1]) In any case, there doesn't seem to be an option in debuggex to make it behave like regex101 for my specific example. [1]http://www.regular-expressions.info/shorthand.html http://www.regular-expressions.info/shorthand.html
- tsergiu 11y agoAh, you're likely on a Windows machine. Debuggex will terminate lines depending on your system. So you would need \s\s to match both \r and \n
- jasode 11y agoInteresting. That's very subtle behavior. (Especially since it sometimes fools one into thinking /g option is not enabled when in reality, it's a CR+LF issue.) I'm not saying your site's interpretation of Windows CR+LF is "wrong" but the other 5 online[1] regex testers don't behave that way on Windows Chrome browser. I also tested the regex and target text on desktop JGSoft RegexBuddy[2]. None of those required "\s\s" instead of "\s". Debuggex at the least, is very idiosyncratic since the majority of the other testers don't treat CR+LF that way. [1]regex testers tried with "([A-Z])\w+\s\w(\d.\d)" on Windows: http://regexr.com/3b22q http://regexr.com/3b22q http://regviz.org/ http://regviz.org/ http://www.rexv.org/ http://www.rexv.org/ https://regex101.com/r/eB5jY1/1 https://regex101.com/r/eB5jY1/1 https://www.debuggex.com/r/mci3WLNmHGTEatf6 https://www.debuggex.com/r/mci3WLNmHGTEatf6 [2]http://i.imgur.com/t2L04mO.png http://i.imgur.com/t2L04mO.png (http://www.regexbuddy.com/ http://www.regexbuddy.com/)