I have got this string:
var str = "[RANKING] Bank President - Main office."
The AIM:
The text between the ']' and ' - ' (notice the spaces) is to be matched in Javascript.
Effort:
So far,
1) I have tried
(?<=\])(.+)(?= -)/gi
This works Perfectly here: http://regexr.com?37abq, however, in javascript I get an Error:
invalid quantifier in firebug.
2) I have also tried:
\](.+) -
This works pretty well here: http://www.rexfiddle.net/TzsXnjQ except that it matches even the ']' and the ' - ', hence, rendering it non-essential to some extents.
3) And Adding something like:
\]^(.+)$ -
The code goes dormant...
Any suggestion is highly appreciated.
Option #2 should work, just get the second match index, eg
var str = "[RANKING] Bank President - Main office."
var matches = str.match(/\](.+?) - /);
if (matches) {
var stringYouWant = matches[1];
}
Option #1 doesn't work because the RegExp library in JS does not support look-behind
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With