Reputation: 2659
I have this string :
"AED 149: "Instant Redemption A 10AED""
How can I have a regex that will get me this text ?
"Instant Redemption A 10AED"
currently I have this
var regEx = new RegExp(currency + ' ' + '[\\d,.]+: (.*)', "ig");
in which currency value is AED
now.
but this return for me "AED 149: "Instant Redemption A 10AED""
as a match
Can I modify my regex to have this result only : "Instant Redemption A 10AED"
?
Upvotes: 0
Views: 60
Reputation: 1852
var str = "AED 149: "Instant Redemption A 10AED"";
str.replace(/[^\:]+\:[^\"]+\"([^\"]+)\"/, "$1");
Upvotes: 0
Reputation: 784958
Transferring my comment into answer for better understanding.
Your regex is fine but global
flag is not needed. You just need to use captured group #1 like this:
var currency = 'AED'
var regEx = new RegExp(currency + ' ' + '[\\d,.]+: (.*)', "i");
var s = 'AED 149: "Instant Redemption A 10AED"'
var m = s.match(regEx);
console.log(m[1]);
//=> "Instant Redemption A 10AED"
Upvotes: 2
Reputation: 67505
If you have always the same format you can get it without regex, just using split :
var my_string = 'AED 149: "Instant Redemption A 10AED"';
my_string.split(':')[1]; //Will return "Instant Redemption A 10AED"
Hope this helps.
Upvotes: 0