Linked Questions
48 questions linked to/from How to escape regular expression special characters using javascript?
642 votes
21 answers
215k views
Is there a RegExp.escape function in JavaScript?
I just want to create a regular expression out of any possible string. var usersString = "Hello?!*`~World()[]"; var expression = new RegExp(RegExp.escape(usersString)) var matches = "...
0 votes
1 answer
143 views
How to escape ^ character in javascript? [duplicate]
For a message in a specific message format (HL7) I'm trying to escape the ^ sign. So the string abc^def^ghi should become abc\^def\^ghi I tried the following ways: > "abc^def^ghi".replace("^", "\^...
-5 votes
2 answers
83 views
Replace certain strings globaly [duplicate]
Sorry, this sounds very basic, but I really can't find on Google. In order to replace contents in a string globally, you can use things like... a.replace(/blue/g,'red') But sometimes you need to ...
36 votes
5 answers
59k views
Fuzzy Searching with Mongodb?
I have managed to set up a search feature in my mongodb app. See the code below. This works very well however it only returns exact results. How would I change my code to make it accept more "fuzzy" ...
18 votes
3 answers
77k views
how to escape characters in nodejs?
I was wondering how would you escape special characters in nodejs. I have a string $what$ever$ and I need it escaped like \$what\$ever\$ before i call a python script with it. I tried querystring npm ...
6 votes
5 answers
15k views
allow parentheses and other symbols in regex
I've made this regex: ^[a-zA-Z0-9_.-]*$ Supports: letters [uppercase and lowercase] numbers [from 0 to 9] underscores [_] dots [.] hyphens [-] Now, I want to add these: spaces [ ] comma [,] ...
2 votes
2 answers
5k views
Regular Expression (case insensitive) on a Variable in an If - JS/Angular [duplicate]
I am trying to find if a value stored in dynamic variable is inside of an array while ignoring case and not using to .toLowerCase() or upper. What I have that works is: if ($scope.favoriteItems....
1 vote
3 answers
9k views
escaping special characters in vba is not working
I don't know why but I can't escape special characters in patterns. If StrTest Like "\[*\]" Then ... It still does not match values like [1234567890]. In other threads I read that "\" is used to ...
0 votes
6 answers
1k views
Failing to replace characters of a string inside a for loop
my code is like that.. function replaceAll(str, from, to) { let result = '' for(let i = 0 ; i < str.length ; i++) if(str[i]===from) { result = str.replace(from,to) } } ...
0 votes
7 answers
5k views
change text color of matching text from input in javascript
Here is my code And I am trying to change the color of any match in the <li> elements that matches the text in the <input> element. So if you type lets say "this is a simple text" the ...
0 votes
3 answers
2k views
Not enough )'s when parsing an user's input that contains one parenthesis
When an user inputs a string that only contains one parenthesis, the Regex.IsMatch() breaks. Inputting a single [ also breaks the program. Regex.IsMatch("John Cena", "Test(", RegexOptions.IgnoreCase) ...
2 votes
1 answer
3k views
jQuery: Real-time search
I am trying to build real-time search project but i am not sure what wrong with my code. if i search "AAA - AAA" a results is show but when i search "TOF0042 - text update + resize" a results not show ...
2 votes
2 answers
2k views
Regex gives error for certain chars
I came across this pen at codePen, and found a bug. If you type in the following chars in the searchbox: ), (, [, +, \, *, ? I get the following error (I entered each char separately): I think the ...
1 vote
2 answers
4k views
Find all words containing specific letters and special characters
Suppose I have a list formed by words including special characters: one <two></two> three# $four etc. I want to find all words in the list that contain specific letters, I've tried to use ...
1 vote
2 answers
3k views
How to match a whole word containing special characters?
I have words to match using only a single pattern. The criteria are one of the following: it contains a number or an underscore at the first letter, OR at least one special character (excluding ...