PCRE and spaces

Using PCRE lib ... to search for a string of words up to a known number of spaces.

i.e. 5 characters of space between tokens.

foo bar foo bar foo bar = between the first foo and the last bar .... there are 5 spaces.

foo bar = it also has 5 spaces between the first foo and the last bar.

Does anyone have a regex to find both of these ... and space variations?

+3
source share
1 answer
\S*(\s\S*){N}

where N is the number of space characters you want. Note that a string of N space characters also matches without anything in between.

+2
source

Source: https://habr.com/ru/post/1795369/


All Articles