This question already has answers here:
How do you split a javascript string by spaces and punctuation?
(4 answers)
How to parse string into words and punctuation marks using javascript
(2 answers)
Closed 9 months ago.
Here I have text something like this:
const string = 'Welcome;;to::';
const string ='Welcome;;';
I want to split this string with ;; and ::;
Expected result:
['Welcome', ';;', 'to', '::']
There will be chance that number of pattern will be increased.
So, is this possible ?
Note: There is no space between words.
Related
This question already has answers here:
Parsing string as JSON with single quotes?
(10 answers)
Execute JavaScript code stored as a string
(22 answers)
Closed 1 year ago.
i have a string as below and i would like to extract the array between the quotes.
mystring = "['str1','str2']"
I tried it with eval and i do not want to use eval in my code. is there any other neat way to do this ?
function parseString(string) {
return string
.split(",")
.map((str) => str.replace("[", "").replace("]", "").replaceAll("'", ""));
}
This assumes none of array indexes includes character ",".
This question already has answers here:
Why do regex constructors need to be double escaped?
(5 answers)
Javascript Regex: How to put a variable inside a regular expression? [duplicate]
(9 answers)
Closed 2 years ago.
I created a RegExp that works as expected however I can't get it to work in a string format
var regex = new RegExp(/IN1\|2.*\r/g);
The regex is supposed to match the line number which will be taken from variable, in above example it would be line number 2. My question is how do I get it to a string format with a variable inside it?
I tried following but it just doesn't work: "IN1\|" + lineNumber + ".*\x0d//g"
Below is a text in case anyone wants to try:
IN1|**1**||QQ|Noth||||||||20190413|20190413||Self\r
IN1|**2**||QQ|Noth||||||||20190413|20190413||Self\r
IN1|**3**||QQ|LHS||||||||20200506|""||Private|||||||||||||||||||||2342344\r
Thank you.
This question already has answers here:
Reference - What does this regex mean?
(1 answer)
Regular expression to match string starting with a specific word
(10 answers)
Regular expression - starting and ending with a character string
(3 answers)
Closed 3 years ago.
I am trying to pull out all the URLs from a text entered by the user by doing the following but am not able to get the desired result.
let regexp = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]#!\$&'\(\)\*\+,;=.]+$/igm;
let str = "https://mysleepyhead.com http://skreem.io";
let array = [...str.matchAll(regexp)];
console.log(array);
Desired output would be
Array ['https://mysleepyhead.com', 'http://skreem.io']
This question already has answers here:
Javascript nth occurance of a string and extract the sub string upto that
(3 answers)
Regex expression to cut string at nth occurrence of character and return first part of string
(3 answers)
Cutting a string at nth occurrence of a character
(5 answers)
Closed 3 years ago.
I want to get a substring that is before the nth point.
For example I have:
let str = "my.string.is.like.that"
Now suppose I want substr= "my.string.is.like" that is all before the 4th point. How can I do that?
You can use split and join,
Second parameter in split is used to limit the number of element to be included in final output
let str = "my.string.is.like.that"
let limited = str.split('.',4).join('.')
console.log(limited)
This question already has answers here:
Regular expression for extracting a number
(4 answers)
Closed 6 years ago.
I have the following string:
PR-1333|testtt
I want to get the number 1333 using regular expressions in javascript. How can I do that?
This will look for numbers in your text.
var text = "PR-1333|testtt";
var number = text.match(/\d+/g); // this returns an array of all that it found.
console.log(number[0]); // 1333