Javascript - multiple regular expression in split method [duplicate] - javascript

This question already has answers here:
How do you match multiple Regex patterns for a single line of text in Java?
(5 answers)
Closed 3 years ago.
'i-love_sushi_andNoodles'.split(/[-_ ]/);
'i-love_sushi_andNoodles'.split(/(?=[A-Z])/);
Basically, I want to combine above two logics as one. and expect results as
["i", "love", "sushi", "and", "Noodles"]
I feel like there must be easy way to do this.
Please help me out
Thanks,

console.log('i-love_sushi_andNoodles'.split(/[-_ ]|(?=[A-Z])/));

Related

Regex after first sign [duplicate]

This question already has answers here:
How can I get query string values in JavaScript?
(73 answers)
Closed 5 years ago.
I'm gonna to write regex or other expression to get coordinates after '='.
My example:
var cords = https://maps.googleapis.com/maps/api/staticmap?center=50.082961,19.966860&zoom=13&size=300x300&sensor=false&markers=color:orange%7C50.082961,19.966860&client=gme-marktplaats&channel=bt_pl&signature=lPDQWiNQ2_mY8xgoVthZHLLYWac=
I want to get 50.082961,19.966860
I know that I could use slice but I think I could write it better with regex.
Simple base for this example: \=(.[0-9]) What's next?
Try this center\=(\d+\.\d+,\d+\.\d+)&
var val = 'https://maps.googleapis.com/maps/api/staticmap?center=50.082961,19.966860&zoom=13&size=300x300&sensor=false&markers=color:orange%7C50.082961,19.966860&client=gme-marktplaats&channel=bt_pl&signature=lPDQWiNQ2_mY8xgoVthZHLLYWac='.match(/center\=(\d+\.\d+,\d+\.\d+)&/)[1]
console.log(val)
But as other's have commented, you likely shouldn't be using regex for this purpose

extracting text between two characters [duplicate]

This question already has answers here:
Regular expression to get a string between two strings in Javascript
(13 answers)
Closed 6 years ago.
Having a string like:
"*this* not that"
I can select *this*
\*(.*?)\*
but I'm not able to get only this.
what I am trying to achieve is to replace -this- by a new string. What's the easiest way to do that ?
you can try:
"*this* not that".replace(/\*.*\*/,'*new_string*');
//"*new_string* not that"

How to separate words within a long string [duplicate]

This question already has answers here:
Split by Caps in Javascript
(4 answers)
Closed 3 years ago.
I have this string variable
var mySentence = "EverythingIsAwesome";
I want it to output: "Everything Is Awesome"
I tried doing mySentence.split(" "); but it stays the same. Then I tried: mySentence.split(" ").join(" "); but it still keeps the sentence together.
Can anyone help me figure out what I'm doing wrong? Many thanks in advance!
You should use match() like this:
mySentence.match(/[A-Z][a-z]+/g);
You will get this array: ['Everything', 'Is', 'Awesome']
To turn it back into a string simply: mySentence.join("");

How to get text equivalent of a number in JavaScript [duplicate]

This question already has answers here:
JavaScript numbers to Words
(28 answers)
Closed 8 years ago.
How to convert numeric number to their text equivalent?
Example:
Suppose if I type 3 or 23 in the text box, I want their text equivalent of three or twenty three, is this possible?
See this answer for more details:
JavaScript numbers to Words
And for a working implementation:
http://javascript.about.com/library/bltoword.htm
This will help you to achieve your task.
Number To Word

Validation for xxx-xxx-xxxx or (xxx)xxx-xxxx [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
A comprehensive regex for phone number validation
Whats the regex for
xxx-xxx-xxxx
or
(xxx)xxx-xxxx
I can create regex for the first one with
/^\d{3}-\d{3}-\d{4}$/
but how to add rule in this so it can also handle the second one?
You can use this: -
/^(?:\(\d{3}\)|\d{3}-)\d{3}-\d{4}$/
I'm no guru but this should do the trick;
/^(\d{3}\-)?(\(\d{3}\))?\d{3}\-\d{4}$/
/^(\(\d{3}\))|(\d{3}-)\d{3}-\d{4}$/

Categories

Resources