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 4 years ago.
Improve this question
Say I have a regex pattern like this:
/^\*HELLO\*/
Just looking for the string "*HELLO*". But then I completely want to change it up so I do this:
/^\*&$&^*2#H\*/
Now I'm looking for the string "*&$&^*2#H*".
How should I change my regex pattern to check for such a complex string with all those different characters?
You should escape the special characters in your pattern, wich are used as tokens by Regex, such as *,^ and $. Or you will end up with an error claiming about a wrong pattern in your regex.
This is how should be your regex: /\*&\$&\^\*2#H\*/.
Furthermore if you are searching for the string with .indexOf() or .includes() methods, you can just pass the string as it is.
str.indexOf("^\*&$&^*2#H\*");
Related
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 2 years ago.
Improve this question
So i want to make a regular expression to validate times between 12:00 and 22:00 but i cant get my head around making expressions and cant find any examples online that i can just swap out examples of. Can anybody help me?
You can use the following regular expression:
^((1[2-9]|2[0-1]):[0-5][0-9]|22:00)$
This is how it works:
^ and $ match start and end of string, and they are there to prevent matching also 112:009 for example (which contains 12:00).
[2-9] matches numbers between 2 and 9, and (a|b) would match either a or b.
Debuggex Demo
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 6 years ago.
Improve this question
Special characters in javascript
Trying to enclose the string containing special characters with in single quotes
i.e gg's in single quotes like 'gg's' or gg's
How to do this? getting error when trying to use above.
just escape the single quote with a backslash
var foo = 'gg\'s';
You can alternate quotation types:
"gg's"
Or you can escape the single quote:
'gg\'s'
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 am surprised that an answer to this is not easily found.
I am in the process of making a JSON schema. I have an object and one of it's properties is a string containing a regex pattern. This property must contain only regex.
So, this question is realistically two questions in one:
What is the regex pattern that describes regex patterns (javascript-compatible please)?
Secondly, how do I apply this to JSON schema (in the "pattern" property or even in the "patternProperty"1 property)?
1: I have no idea what purpose would require you to apply this in "patternProperty", but someone out there could find it useful
NOTE: Since, JSONschema is JSON and JSON is JavaScript-based, JavaScript scripters may find the solution (to the JSONschema-side of the question), as well as the problem, useful in their scripts.
Regexes can have nested parentheses.
Therefore, they are not describable by a regular expression.
Sorry.
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 want to split strings by commas and dots using javascript. For example, a string of "10,256,326.26" would turn into ["10", "256", "326", "26"] after getting split.
Which regex can I use for this?
You can use a character class containing all characters on which you want to split
var s = "10.269,69";
document.write(s.split(/[,.]/))
You can use split() with a regex:
console.log(str.split(/,|\./));
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 8 years ago.
Improve this question
I want a regular expression that checks if a string contains only the allowed characters. The allowed characters are alphanumeric and the special characters (),#\/\-. I used this expression, and it is working fine.
/^([A-Za-z0-9 .(),#\/\-]*)+$/
Now I don't want the string to start with space or any disallowed characters, but it can have space in the middle. Also, the string may not consist of only special characters; it should have at least one alphanumeric character.
Can someone help me understand how to adapt the regex I am using to check these additional constraints?
^(?=[a-zA-Z0-9])([A-Za-z0-9 .(),#\/-]*)+$
This should do it.