0

I trying to remove some string from string which I have.

I have following string.

"[1fe3-46675-be1a-cd97084b]^Some Text@ dsd dsds [4j34-46675-be1a-cd97854b]^Another Text@"

I want to remove text between ^ @ including that character.

Output should be "[1fe3-46675-be1a-cd97084b] dsd dsds [4j34-46675-be1a-cd97854b]"

I used following but, not removing that string.

let str = "[1fe3-46675-be1a-cd97084b]^Some Text@ dsd dsds [4j34-46675-be1a-cd97854b]^Another Text@"

str = str.replace(/^.*@/g, '');

console.log(str);

3 Answers 3

2

You can do it with this regex.

let stringsS = "[1fe3-46675-be1a-cd97084b]^Some Text@ dsd dsds [4j34-46675-be1a-cd97854b]^Another Text@"
let regex = /\^(.*?)\@/gi

console.log(stringsS.replace(regex,''));

Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

str = "[1fe3-46675-be1a-cd97084b]^Some Text@ dsd dsds [4j34-46675-be1a-cd97854b]^Another Text@";
replacedStr = str.replace(/\^[^@]*\@/g, '');
console.log(replacedStr)

Comments

0

Escape the ^ as in:

str = str.replace(/\^.*@/, '');

The ^ means something in regex and must be escaped if you want it to be treated as normal character

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.