Trying to understand and replicate a text highlighter in JS and came across this particular command:
textToSearch = textToSearch.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");
as shown in the photo below. What does the set of symbols followed by a "/g " mean ? What does β\$&β mean ???
HTML code

JS code
ilenia
2
thatβs a regular expression with a g
(global) flag, the flags go after the closing /
of the regular expression
this is replace syntax, letβs look at the documentation:
https://devdocs.io/javascript/global_objects/string/replace
$&
will add the matched string in the string to substitute
1 Like
system
Closed
4
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.