Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
With this code
"test\536".replace(/'/g, "")
I would expect there is no different to the original string, because there is no single quote. But I get this instead
"test+6"
When I run this on a string with single quote, it works as expected
"test'536".replace(/'/g, "")
"test536"
The problem is in your string, in JavaScript strings \ is used to escape the following character. so if you want to prevent this behavior you should escape it using another slash, it will be \\:
"test\\536".replace(/'/g, "")
console.log("test\\536".replace(/'/g, ""));
console.log("test'536".replace(/'/g, ""));
Hope this helps.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying to get a js file to convert a .h file to a .cs file. I go to this point and it says "gencsinc.js(26, 153) Microsoft JScript compilation error: Unterminated string constant" the line that is 26 is below.
fout.Write('using System;\r\n\namespace PortableDeviceConstants\r\n\{\r\n\class PortableDevicePKeys\r\n\{\r\n\static PortableDevicePKeys()\r\n\{\r\n\');
You are escaping last quote character:
...\');
Just remove the slash \ to close the string.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
'John David Alice Jack Jim'
I want to select all spaces in this text. There are multiple spaces between David and Alice...and between Jack and Jim.
\s+ doesn't work as you can see here
Solved: It turns out that, I have forgot to add 'g'.
Use: /\s+/g
/g (global) All matches.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have this string
24.733835, 121.34365500000001:AP-54184
i want to spilt the string by ':' , but why can't spilt the string
var newarray= '24.733835, 121.34365500000001:AP-54184'.spilt(/:/);
document.write(newarray[0]+","+newarray[1]+"<br>");
Is there anything wrong with my code ?
There is no function spilt() unless it's part of the Milk class. You want split(':')
You have a typo in your code, it should be .split(), not .spilt()...
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
Just trying to create a simple Regex validation with JavaScript. I want to validate the phone number in the following format "+91-xxx-xxx-xxx", where the country code is fixed.
I have used the following regex pattern
/^[91]-\d{3}-\d{3}-\d{3}$/
But it isn't working. Here is my jsfiddle
Can you help?
You need to add + at the start and also you have to remove the character class which has 91
^\+91-\d{3}-\d{3}-\d{3}$
DEMO
This [91] would match a single character either, 9 or 1 but not 91. To match 91, you need to getout the number 91 from the character class. + is a meta character in regex, you need to escape it to match a literal + symbol.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have stumbled across this code:
"".length
It should obviously return 0, but for some reason returns 1337. Is this some kind of trick i dont know?
The code is:
Open quote
Unicode Character 'ACTIVATE ARABIC FORM SHAPING' (U+206D) ×1337
Close quote
.length
Since the string is made of 1337 "invisible" characters, the length is 1337.