Search code examples
regexnaming-conventionsregex-lookaroundslookbehind

Naming convention of regex, lookahead and lookbehind


Why is it counter intuitive?

/(?<!\d)\d{8}(?!\d)/, here (?<!\d) comes first, but called lookbehind, (?!\d) next, but called lookahead. All are counter intuitive.

What's the reason to name it this way?


Solution

  • It's counterintuitive because there is no consensus whether time goes from front to back or back to front and you simply has a different mindset.

    In English we say "Leave the past behind", yet "past" is something that happens "before" (fore = front).