why does vim's regex syntax have two word boundaries?
Asked Answered
P

1

5

Javascript's regex syntax only has one word boundary: \b.

Vim's regex syntax has two: \< (start of word) and \> (end of word).

Can anyone give me an example of a search that can be achieved with the vim style word boundaries but could not be achieved with the javascript style?

Or is it the case that regex syntaxes that have a single word boundary can do just as much but there is some other advantage to having start and end boundaries?

Pires answered 5/11, 2015 at 8:16 Comment(1)
\< would be written in javascript as \b(?=\w), there's no case where you could not achieve a match. It's just the way it's defined.Svoboda
W
7

The syntax used in Vim comes from vi which gets it from ex which gets it from ed which was one of the first real world implementation of regular expressions. (Yes there are holes in that timeline.)

The syntax used in many programming languages — JavaScript included — comes directly from Perl.

Both vi (and other clones later on) and Perl (and PCRE later on) have added a lot of features to the POSIX standard but each implementation unfortunately followed its own path. The Perl/JavaScript/PCRE branch of the tree started a lot later than the ed/sed/ex/vi/Vim one.

So I would reframe your question like this:

Why did Perl, JavaScript, and PCRE chose to have a single word boundary when older, more established, implementations had two?

Wickiup answered 5/11, 2015 at 9:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.