开发者

PHP Regex - Finding two consecutive words with unknown number of spaces (" ") between them

I am trying to create a PHP REGEX that will match if two words appear next to each other with ANY number of spaces between them.

For example, match "Daniel   Baylis" (3 spaces between 'Daniel' and 'Baylis'). I tried with th开发者_Python百科is but it doesn't seem to work:

"/DANIEL[ ]{1,5}BAYLIS/" (this was to check up to 5 spaces which the most I expect in the data)

and

"/DANIEL[ ]{*}BAYLIS/"

I need to extract names from within larger bodies of text and names can appear anywhere within that text. User input error is what creates the multiple spaces.

Thanks all! - Dan


/DANIEL[ ]+BAYLIS/ should do... + will glob one or more occurence of the previous character(-class), in this case, litteral space.

Also, assuming you want to match regardless of the case, you'll need to adjust your regex to be case-insensitive, which I'm not sure how to do in PHP (it depends on which flavor of regex you use... Long time since I last touched that...)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜