firasdib / Regex101

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

JavaScript bug in the explanation - Character groups does not support back references #1992

Closed briandamgaard closed 1 year ago

briandamgaard commented 1 year ago

JavaScript does not support back references from inside a character class. An example:

RegEx Flavor: JavaScript

Regular Expression: (a|b)[c\1d]e

Test String: aae

Match Information: Your regular expression does not match the subject string.

Explanation: \1 matches the same text as most recently matched by the 1st capturing group

The highlights of the various regex parts in the regular expression match the explanation of "\1".

The explanation and the highlighting are wrong. JavaScript does not support back references from inside a character class.

The match information for the example is correct, i.e., "aae" doesn't match the regular expression.

working-name commented 1 year ago

Hi @briandamgaard,

As far as I know you cannot use backreferences inside a character class. If you manage to get this going in your browser console or a jsfiddle please let me know.

I'm marking this as invalid for now.

briandamgaard commented 1 year ago

As far as I know you cannot use backreferences inside a character class.

That is precisely what I said. You have not understood the point yet, which is that the "Explanation" field on the webpage falsely says that the "\1" inside the character class IS a back reference. That is a bug.

working-name commented 1 year ago

My apology, I misunderstood. You're right that's not normal behavior for the javascript flavor.

firasdib commented 1 year ago

Thank you, I will push a fix for this.