4 ms·
Tried it with one of my blog posts: https://learnbyexample.github.io/python-regex-surprises/ https://learnbyexample.github.io/python-regex-surprises/ >This pos
by asicsp 4y ago
Tried it with one of my blog posts: https://learnbyexample.github.io/python-regex-surprises/ https://learnbyexample.github.io/python-regex-surprises/
>This post provides a few examples of regular expressions that may surprise the reader. It covers topics such as the difference between the $ and \Z anchors, the use of start and end arguments for compiled methods, the behavior of undefined escape sequences, the use of octal and hexadecimal escapes in the replacement section, the behavior of quantifiers, and the difference between greedy and possessive quantifiers. It also highlights the importance of using keyword arguments when using the sub() function, and the need to use the regex module's constants when using the regex module. Overall, this post provides a great overview of some of the nuances of regular expressions.
At first I thought it was just making use of subheadings but on a closer look it does pick up points from the content. I think this could be very useful in trying to come up with short description for meta tags.
Edit: just saw that there's also a "Key Moments" button too!
>- The $ and \Z anchors are not equivalent. The $ anchor can match both the end of string and just before \n if it is the last character, while \Z will only match the end of string.
>- You can specify start and end index arguments for compiled methods.
>- When using the re.MULTILINE flag, the ^ and $ anchors will match at the start and end of every input line, and also after the last newline character.
>- Undefined escape sequences will raise an exception.
>- Only octal escapes are allowed inside raw strings in the replacement section.
>- Referring to the text matched by a capture group with a quantifier will give only the last match, not the entire match.
>- \b[a-z](on|no)[a-z]\b is not same as \b[a-z][on]{2}[a-z]\b.
>- (a*|b*) is not same as (a|b)*.
>- You should always pass flags as a keyword argument for the sub() function.
>- When using the regex module, the constants should also be used from the regex module.