I have a string that looks like this: "XaXbXcX". I'm looking to match any lowercase letters surrounded by X on either side. I tried this in Python, but I'm not getting what I'm looking for:
import re
str = "XaXbXcX"
pattern = r'X([a-z])X'
matches = re.findall(pattern, str) # gives me ['a', 'c']. What about b?
You can use a lookbehind assertion:
pattern = r'(?<=X)([a-z])X'
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