Answers for "positive lookahead regex"

5

regex lookbehind

# Positive lookahead
q(?=u)   # Matches the letter "q" if "q" is followed by the letter "u"
# Negative lookahead
q(?!u)   # Matches the letter "q" if "q" is NOT followed by the letter "u"
# Positive lookbehind
(?<=a)b  # Matches the letter "b" if "b" is preceded by the letter "a"
# Negative lookbehind
(?<!a)b	 # Matches the letter "b" if "b" is NOT preceded by the letter "a"
Posted by: Guest on June-30-2021
0

Regex lookahead

# Can use a regex,so this Lookahead and Lookbehind ' to see that's there a word character on each end.

import re
import json
 
s = "[[('name', 'productname_0'), ('type', 'html'),('content', 'O'Cornor')],[('name', 'productname_1'), ('type', 'html'), ('content', 'Philp's')]]"
result =  re.sub(r"(?<=w)'(?=w)", r"\'", s)
print(result)
d = json.dumps(result)
print(json.loads(d))
Posted by: Guest on May-14-2021

Code answers related to "positive lookahead regex"

Browse Popular Code Answers by Language