Zero-width assertions

Published: 01 January 2022
on channel: Regex Quickies with Wiktor Stribiżew
419
19

Zero-width assertions are common regex constructs that allow matching patterns in specific contexts: at the start or end of a string or a word, after a certain word or before a specific character. You must have heard and used anchors, word boundaries, lookaheads and lookbehinds in your patterns, and these are all examples of zero-width assertions.

REGEX FIDDLE: https://regex101.com/r/JlOmlT/1

FURTHER LINKS
https://rexegg.com/regex-boundaries.html - Word boundaries
https://rexegg.com/regex-anchors.html - Anchors
https://www.regular-expressions.info/... - Lookahead and Lookbehind Zero-Length Assertions
https://rexegg.com/regex-lookarounds.... - Mastering Lookahead and Lookbehind
https://stackoverflow.com/a/43232659/... - match anywhere but at the string start
https://stackoverflow.com/a/35271748/... - match a line feed char if not preceded with semi-colon
https://stackoverflow.com/a/40942385/... - match until first instance of certain character
https://stackoverflow.com/a/32477224/... - ensure the whole string has a specific length (`\A(?=.{1,15}\Z)`)
https://stackoverflow.com/a/51134786/... - match up to a char or end of string (`(?=&|$)` = `(?![^&])`)


On this page of the site you can watch the video online Zero-width assertions with a duration of hours minute second in good quality, which was uploaded by the user Regex Quickies with Wiktor Stribiżew 01 January 2022, share the link with friends and acquaintances, this video has already been watched 419 times on youtube and it was liked by 19 viewers. Enjoy your viewing!