firasdib / Regex101

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

Capture groups don't highlight for javascript #533

Closed Gyomo closed 8 years ago

Gyomo commented 8 years ago

Capture groups don't highlight at all if Javascript is the selected language. And it doesn't appear to matter if the checkbox is checked in settings for any language. PHP and Python always highlight, while Javascript never does. Perhaps "highlight groups" doesn't mean what I think it does... but I would expect all three flavors to behave the same regardless (the actual groups that match are the same, just not the highlighting)

nhahtdh commented 8 years ago

This is by design. The JavaScript API doesn't expose any way to access the start and end index of the capturing groups - it only gives the content of the capturing groups. Therefore, the most we can do is show the match content on the right panel, and highlight the main match.

Gyomo commented 8 years ago

Even a close approximate would be nice. It would be even closer if the approximate happened to match the other two flavors. That is to say if the python and/or the php flavor give the start and end index as that exactly matches a javascript test --> sTestText.substring( pythonStartIndex, phpEndIndex ) I would be pretty confident to just have an asterisk nearby marking it as approximate.

That said I can also see why you might not want to bother. As it is I just toggle between php and javascript to see that matches and it works just fine (but obviously there could be differences).

Anyway, great tool. Than you so much for your time.

darkred commented 8 years ago

Capture groups don't highlight at all if Javascript is the selected language. And it doesn't appear to matter if the checkbox is checked in settings for any language. PHP and Python always highlight, while Javascript never does. Perhaps "highlight groups" doesn't mean what I think it does... but I would expect all three flavors to behave the same regardless (the actual groups that match are the same, just not the highlighting)

This is by design. The JavaScript API doesn't expose any way to access the start and end index of the capturing groups - it only gives the content of the capturing groups. Therefore, the most we can do is show the match content on the right panel, and highlight the main match.

If I'm not mistaken, groups are always highlighted in PHP and Python, even if the setting HIGHLIGHT GROUPS is disabled. And because in Javacript they are never highlighted, I'd like to make a suggestion, please:

// PHP and Python
document.querySelector('#highlight_interaction').disabled = true;
document.querySelector('#highlight_interaction').checked = true;
document.querySelector('#colorizer_themes > label:nth-child(10)').style.color = "black";

// Javascript
document.querySelector('#highlight_interaction').disabled = true;
document.querySelector('#highlight_interaction').checked = false;
document.querySelector('#colorizer_themes > label:nth-child(10)').style.color = "lightgray";
nhahtdh commented 8 years ago

@darkred That's a separate issue and should belong in a separate bug report.

darkred commented 8 years ago

@nhahtdh Ok. Please check issue #550