Woundorf / foxreplace

Replace text in webpages
https://addons.mozilla.org/firefox/addon/foxreplace/
GNU General Public License v3.0
89 stars 22 forks source link

ECMAscript regex not implemented in exactitude: is there a FoxReplace regex style available? #346

Closed retropele closed 1 year ago

retropele commented 1 year ago

Hi,

Thanks for the amazing addon.

I try to implement certain regex rules that I can test to be working in the supplied example test site regex101, under ECMAscript, that just don't work in FoxReplace when I copy and paste them across even.

Relevant issues in the github that have been resolved are often from years ago so I can't trust the regex in them to work.

I know FoxReplace isn't the exact same as ECMAscript, but is there a definitive guide anywhere on the regex? Could one be supplied or could I be signposted to one?

For the record, these are the commands I cannot get to be functional. I've removed the "gm" (as I figure it's redundant in FoxReplace) but I've tried it with both to no avail:

/perspective. Inaccessible/ TO /perspective.\nInaccessible/

/boarded. Insulation/ TO /boarded.\n\nInsulation/

/.\nLocated in the/ TO /, located in the/

I also can't seem to use the "word" wildcard with + or to extend it. A guide would really help, as just being able to work my way around the regex here has the potential to make my job a lot* easier!

Thanks for a whole decade of development, help and assistance.

Woundorf commented 1 year ago

Hi,

The regex is created in this way (https://github.com/Woundorf/foxreplace/blob/master/scripts/core.js#L55):

this.regExp = new RegExp(this.input, this.caseSensitive ? "g" : "gi");

Thus it supports exactly the same as Firefox. But from your comment about the "gm" I think maybe you are including the slashes in the input field? If that's the case you have to remove them, otherwise it will try to match them.

In other words, if you put perspective in the "Replace" field it's the equivalent of /perspective/g in Javascript (or ECMAscript).

retropele commented 1 year ago

Thanks so much for your speedy response. :)

I have wondered if that was my problem, and have tried that myself, but I will let you know how it goes.

So, in other words, can I basically trust this will be the same as any documentation of regex in Firefox generally?

Woundorf commented 1 year ago

So, in other words, can I basically trust this will be the same as any documentation of regex in Firefox generally?

Yes.