Reputation: 502
I have a regex rule [A-Z|a-z]"[A-Z|a-z]
.
When applying it to
Mother"s day passed!
the regex returns r"s
, but I'm only interested in the "
char that has to fall in the middle of alphabetic characters.
How can I do that with regex?
Upvotes: 2
Views: 31
Reputation: 7875
You can use Positive Lookbehind as below
(?<=\b)"
\b
assert position at a word boundary
"
matches the character "
literally
Upvotes: 0
Reputation: 627292
You may use lookarounds, a lookbehind coupled with a lookahead:
(?<=[A-Za-z])"(?=[A-Za-z])
Here, (?<=[A-Za-z])
positive lookbehind will require a letter on the left and the (?=[A-Za-z])
positive lookahead will require a letter to the right of the double quotation mark.
See the regex demo.
BTW, note that [A-Z|a-z]
matches ASCII letters and a |
char, since the |
inside a character class loses its special meaning of an alternation operator.
Upvotes: 1