Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
117
rated 0 times [  122] [ 5]  / answers: 1 / hits: 127072  / 12 Years ago, wed, february 20, 2013, 12:00:00

I need to check whether a word starts with a particular substring ignoring the case differences. I have been doing this check using the following regex search pattern but that does not help when there is difference in case across the strings.



my case sensitive way:



var searchPattern = new RegExp('^' + query);
if (searchPattern.test(stringToCheck)) {}

More From » regex

 Answers
20

Pass the i modifier as second argument:



new RegExp('^' + query, 'i');


Have a look at the documentation for more information.


[#80105] Tuesday, February 19, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deonkalvinw

Total Points: 409
Total Questions: 96
Total Answers: 89

Location: Saint Pierre and Miquelon
Member since Sun, Nov 27, 2022
2 Years ago
deonkalvinw questions
Sun, Feb 6, 22, 00:00, 2 Years ago
Tue, Dec 28, 21, 00:00, 2 Years ago
Sun, Aug 22, 21, 00:00, 3 Years ago
Sun, Mar 7, 21, 00:00, 3 Years ago
;