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.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 7 years ago.
Improve this question
I've made a regular expression for getting all background image patterns:
Pattern p = Pattern.compile("background(-image)?:[\\s]?url[\\s]*\([\\s]*(?<url>[^\)]*)[\\s]*\)[\\s]*");
But this will failed in this case, because of #66cc33:
background:#66CC33 url(images/bg-topbar.png)
Can anyone help me to modify my pattern?
You can use this regex, with basically doesn't care about anything but the url() content:
background(-image)?:.*?url\(\s*(?<url>.*?)\s*\)
This seems like a duplicate of this question https://stackoverflow.com/a/20857448/5856415, you should try the regex given in that answer to simply select text between the brackets.
/\((.*?)\)/)[1].replace(/('|")/g
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.
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 7 years ago.
Improve this question
I need a regex for an input pattern that doesn't allow spaces and a "." followed by a "-"
i.e.:
this-is-valid.com
this is not valid
this.-is-also-not-valid
this-.is-also-not-valid
The key will be defining the group of characters that are allowed on the left and right sides and just adding "-" to the right-hand-side. I've just used \w here:
\b((?:\w|-)+\.\w+)(?:[^-]|$)
[Live Example]
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.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm asking my users to write their domain name.
I'm looking for inputs of these types (=good):
http://www.Domain.com
http://Domain.com
https://www.Domain.com
https://Domain.com
www.Domain.com
Domain.com
http://no.matter.how.many.Domain.com
https://no.matter.how.many.Domain.com
no.matter.how.many.Domain.com
http://www.Domain.com/
https://www.Domain.com/
http://no.matter.how.many.Domain.com/
https://no.matter.how.many.Domain.com/
www.Domain.com/
Domain.com/
I'm want to reject any input that not in this format.
Bad inputs, for example:
http://www.Domain.com/page
http://www.Domain.com/page.html
http://www.Domain.com/page/page2
and so on...
Can you help me with a suitable RegEx?
Thank you!
You can use this regex
^(https?://)?[^/]+/?$
^depicts the start of string
$ depicts the end of string
? matches preceding group or char optionally..
Solution:
(https?://)?(www.)?([A-Za-z]+\.){1,}([A-Za-z]{2,})/?