Enclose a string containing special characters with in single quotes [closed] - javascript

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'

Related

Regex pattern with special characters, digits and letters all combined [closed]

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\*");

How to split a JavaScript String by commas and dots? [closed]

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(/,|\./));

Only if contains >< /!a-zA-Z or some of them with regular expression [closed]

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 7 years ago.
Improve this question
I need to check string if contains >< /!a-zA-Z or some of them (Also contains space). The only thing I know is a-zA-Z i need an example in C# or Javascript.
Use a "character class".
/[>< \/!a-zA-Z]/
Note that I've escaped the forward slash, since we're using forward slashes as delimiters.

search for the same number in the beginning and the end of a string [closed]

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 8 years ago.
Improve this question
I'm trying to write regexp to find a string who start and ends with the same number like so :
2aldkc2 <----
4alou4 <----
edit , i forget to motion what i have tried so far :
^(\d).^([^h].*$)
but this doesn't work
Use capturing group.
^(\d).*\1$
The regex captures the first digit and match that particular line only if the last character is also the same as the one captured.
DEMO

Regular Expression for checking at least one alphabet or number [closed]

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.

Categories