I am not able to understand how these regex works and when they are used. I haven’t found concrete examples of these regex on python website. I know sed awk but haven’t used these type of regex there
(?=...)
(?<=...)
(?(id/name)yes-pattern|no-pattern)
(?=...)is a positive lookahead assertion. It matches if there is the part in parentheses after?=matches at the current position, but it will not consume any characters for the match. E.g. the regexa(?=b)will match anafollowed by ab, but won’t return thebas part of the match.(?<=...)is the same, but a look behind, i.e. it looks backwards. Again, it doesn’t consume anything.(?(id/name)yes-pattern|no-pattern)is a conditional. If the named groupid/namematched, then the string must matchyes-patternat this point, otherwiseno-pattern.To be honest, though, those are quite advanced features and I cannot remember ever having used a conditional. Lookaround is more common, but often very constrained by the regex engines, e.g. lookbehind can only be done with fixed-length strings in many cases.