I'm having trouble getting this Javascript Regular Expression to work.
What i want is to find a character that starts with @"
has any characters in the middle and ends with "
. I will also need it in a single quote from.
The tricky part for me, is that it cant be starting with @"
and ending with "
because the string it's looking through could look like [UIImage imageNamed:@"glass-round-red-green-button.png"]
.
So far what i have is this.
regex: new RegExp('\\@"?\\w+\\b"*', 'g')
Try this regular expression:
/@(["'])[^]*?\1/g
An explanation:
@(["'])
matches either @"
or @'
[^]*?
matches any arbitrary character ([^]
contains all characters in opposite to .
that doesn’t contain line-breaks), but in a non-greedy manner\1
matches the same character as matches with (["'])
Using the literal RegExp syntax /…/
is more convenient. Note that this doesn’t escape sequences like \"
into account.
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