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
How do I detect strings in Javascript that end with (number-number) at end of string?
Examples of strings I'm looking to match:
High (0-22)
Low (23-100)
Regex
/.*\(\d+-\d+\)$/
Explanation
. = any character
* = zero or more times
\(,\) = literal parentheses (must escape with backslash or it will be interpreted as a regex control character)
\d = digit
+ = one or more times
- = literal hyphen
$ = end of line
Links
Here is a jsfiddle to play with.
http://www.regular-expressions.info/ has lots of useful information.
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 8 months ago.
Improve this question
I am trying to figure how I can search for a pattern that gives me only digits or digits followed by only one letter. I know I can use /\D\g to find only digits but I dont know how to find digits with only one letter after it. The letters can only be the following:['a','A','b','B','c','C','d','D','n','N','e','E','s','S','w','W']
const testPattern = /[A-Za-z][0-9]/
console.log('item_10a_object10a'.pattern(testPattern))
First, you need to group the whole thing with (), and end with /g so it matches multiple groups.
If you want digits first then a number, you need to put the letter block after the numbers: ([0-9][A-Za-z])
If you want multiple digits to match, you need a + after the numbers block: [0-9]+
All together: /([0-9]+[A-Za-z])/g
For reference, \d does the same thing as [0-9], so you could do /(\d+[A-Za-z])/g instead
LPT: use regex101 to build and test regex queries
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have just created a snippet generator tool for Sublime Text, Atom and VS Code, you can find it here: https://snippets.now.sh.
Snippets for these apps need to have the $ escaped e.g. $('.class'), but not when it is used for placeholders e.g. ${1:foo}.
What is the regex to match only occurrences of the $ when it is not followed by a {?
Just to reiterate:
Match this: $foo
Don't match this: ${foo
Use the following regex pattern:
\$(?!{).+\b
(?!{) - negative lookahead assertion, ensures that $ is not followed by {
https://regex101.com/r/qQZIZQ/2
Additional case with substitution for the condition :
$ dollar signs need to be escaped, like so \$, but not when followed
by {, like so; ${
\$(?!{)(.+\b)?
substitution: \\$0
https://regex101.com/r/qQZIZQ/4
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 want Javascript regex for all strings that start with $$ and ends with $$
example:
$$hello$$
$$world$$
^\${2}.*?\${2}$
How this works: first, you look for two dollar signs, then, it allows any input, and then it looks whether the string ends with two dollar signs.
A pattern like this should work:
^\$\$.*\$\$$
This will match the beginning of the string (^) followed by $$, followed by zero or more of any character, followed by $$, and the end of the string ($). For example:
/^\$\$.*\$\$$/.test('$$hello$$') // true
If you're looking for a substring of a larger string which matches this pattern, use something like this:
\$\$.*?\$\$
This will match $$, followed by zero or more of any character, non-greedily, followed by $$. For example:
/\$\$.*?\$\$/.exec('print "$$hello$$"') // ['$$hello$$']
But for something this simple, you can just use plain old string manipulation:
var string = '$$hello$$';
var result = (string.substr(0, 2) == '$$') && (string.substr(-2) == '$$'); // true
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a following requirement to only allow capital letters and , in a javascript form . I am unsure on how to check for special characters and script tags . I have written the following code . I do not want to allow characters such as $,%,& etc .
var upperCase= new RegExp('[A-Z]');
var lowerCase= new RegExp('^[a-z]');
var numbers = new RegExp('^[0-9]');
if($(this).val().match(upperCase) && $(this).val().match(lowerCase) && $(this).val().match(numbers))
{
$("#passwordErrorMsg").html("OK")
}
Based on what you've given us, this may suit the bill. It will determine if any characters are not in character classes a-z, A-Z or 0-9 but note this will also treat é or similar characters as rejected symbols.
So if the value is 'test_' or 'test a' it will fail but it will pass for 'testa'. If you want it to accept spaces change the regex to /[^a-zA-Z0-9 ]/.
if(!/[^a-zA-Z0-9]/.test($(this).val())) {
$("#passwordErrorMsg").html("OK");
}
This may be helpful.
javascript regexp remove all special characters
if the only characters you want are numbers, letters, and ',' then you just need to whitespice all characters that are not those
$(this).val().replace(/[^\w\s\][^,]/gi, '')
This link may be helpful:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
It has a lot of information on JS Regexps.
For a dollar sign ($), the regexp syntax would be: \$. You need to escape the special character so it is read as a literal. The syntax would be the same for the other special characters, I believe.
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
For my website , i need a REGEXP in java script for validation TITLE which can take alphabates, digits and Special char set [, / ( ) & - : . space], but if any user enter only single and double spaces or single or double .. like [..] in title or double digit [1 2] then it's should not allowed, atlest one aplhabate is required. please help
You can use this pattern:
^[-a-z0-9,/()&:. ]*[a-z][-a-z0-9,/()&:. ]*$
This will match any number of your special characters followed by a Latin letter, followed by number of your special characters. It's effectively equivalent to [-a-z0-9,/()&:. ]+ except it requires at least one [a-z] somewhere in the string.
Of course, you need to escape the \ when written as a regex literal in javascript, and you probably want to use the i flag for case-insensitive matching:
var pattern = /^[-a-z0-9,\/()&:. ]*[a-z][-a-z0-9,\/()&:. ]*$/i