0

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" ?

3
  • Use captured group #1 for "Instant Redemption A 10AED" Commented Dec 1, 2015 at 7:51
  • how my regEx variable will be then ? "Instant Redemption A 10AED" is not a fixed text it could be any string, but this one is fixed AED 149: in which AED = currency Commented Dec 1, 2015 at 7:58
  • 1
    Please post full relevant code. Commented Dec 1, 2015 at 8:07

3 Answers 3

2

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"
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0
var str = "AED 149: "Instant Redemption A 10AED"";
str.replace(/[^\:]+\:[^\"]+\"([^\"]+)\"/, "$1");

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.