字串與正規

擷取、取代、比對與正規表達式。

12 / 12 題 · 依票數排序

5.5k

How do I replace all occurrences of a string?

Given a string: string = "Test abc test test abc test test test abc test test abc"; This seems to only remove the first occurrence of abc in the string above: string = string.repl…

2009javascriptstringreplace·3 重點答案·4.6M 次瀏覽
2.9k

Generate a string of random characters

I want a string of fixed length, composed of characters picked randomly from a set of characters e.g. [a-zA-Z0-9] . How can I do this with JavaScript?

2009javascriptstringrandom·3 重點答案·3.2M 次瀏覽
2k

How do you use a variable in a regular expression?

I would like to create a String.replaceAll() method in JavaScript and think using a regex would be the most terse way to do it. However, I can't figure out how to pass a variable…

2009javascriptregex·3 重點答案·1.4M 次瀏覽
1.8k

How to check if a string "StartsWith" another string?

How would I write the equivalent of C#'s String.StartsWith in JavaScript? var haystack = 'hello world'; var needle = 'he'; haystack.startsWith(needle) == true Note: This is an old…

2009javascriptstringstartswith·3 重點答案·1.1M 次瀏覽