neaumusic / selection-highlighter

browser highlighter for code analysis
BSD 3-Clause "New" or "Revised" License
82 stars 15 forks source link

Fixed special characters not being escaped for the regex usage #20

Closed evandrocoan closed 5 years ago

neaumusic commented 5 years ago

I'm wondering if this is an issue with the number of \ being used, I noticed I had to use something ridiculous, like 3 or 4 backslashes What does replacing with '\\$&' do?

neaumusic commented 5 years ago

Realizing that I think I see what you mean -- if you'd selected text that is parsed into new RegExp() you wouldn't want those characters used as special tokens, just plain text

neaumusic commented 5 years ago

Got it from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter Looks good to me, thank you