Reputation: 19341
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);
Upvotes: 0
Views: 43
Reputation: 815
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,''));
Upvotes: 2
Reputation: 1433
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
Upvotes: 0
Reputation: 1070
Try this:
str = "[1fe3-46675-be1a-cd97084b]^Some Text@ dsd dsds [4j34-46675-be1a-cd97854b]^Another Text@";
replacedStr = str.replace(/\^[^@]*\@/g, '');
console.log(replacedStr)
Upvotes: 1