How to remove all + signs from string? [duplicate] - javascript

This question already has answers here:
What special characters must be escaped in regular expressions?
(13 answers)
Closed 2 years ago.
I have a string that looks like KATIE+DAMAN-SUZANNE+DANIELS
How do I replace both + signs? I tried the following which does not work.
string.replace(/+/g, ' ');

string.replace(/[^a-zA-Z ]/g,'')
You have tried this it's working

Related

Regex to capture digits after pattern [duplicate]

This question already has answers here:
How can I use backslashes (\) in a string?
(4 answers)
Why do regex constructors need to be double escaped?
(5 answers)
Closed 2 years ago.
I can't seem to find the issue with this code:
const regex = "/tel:\+61(\d+)/g";
const subscriberNumber = senderAddress.match(regex);
For input text, senderAddress = tel:+619123456789 the subscriberNumber is null.
What's causing it to return null?
You haven't escaped the + in 61. + is used as a concatenation operator too.
I don’t think the parentheses around \d+ are necessary.

RegExp with variable in a string format [duplicate]

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.

split with regex is not returning correct repsonse [duplicate]

This question already has answers here:
My regex is matching too much. How do I make it stop? [duplicate]
(5 answers)
Regex to first occurrence only? [duplicate]
(4 answers)
Closed 4 years ago.
I have a string
var str3 = "[a,b,c] there [s,b,c] how are u";
What i want is [there, how are u] but I am getting ["", "how are u"], when splitting with str3.split(/\[.*\]/);
Any idea how i shud do it?
You shouldn't be greedy:
str3.split(/\[.*?\]\s*/);
:-)

replace the character ' for "" in a string in javascript [duplicate]

This question already has answers here:
Double quote in JavaScript string
(4 answers)
Closed 4 years ago.
I am trying to write it like this:
str.replace("'", """)
but it gives me an syntax error, how to properly write this?
use escape str.replace("'", "\"")

Regex working in every online parser but not in JS? [duplicate]

This question already has answers here:
Why do regex constructors need to be double escaped?
(5 answers)
Regex created via new RegExp(myString) not working (backslashes)
(1 answer)
Javascript RegEx Not Working [duplicate]
(1 answer)
Closed 5 years ago.
I've created regex to parse football match score:
(0|[1-9]\d*\s)(:)(\s0|[1-9]\d*)
When I try:
let scoreRegex = new RegExp('(0|[1-9]\d*\s)(:)(\s0|[1-9]\d*)')
scoreRegex.exec('Team One 5 : 0 Team Two')
I get null instead of expected 3 groups. Any online parser out there validates my regex and matches the input string.
https://www.regextester.com/ +
https://regexr.com/ +
What am I missing?

Categories