开发者

Regex including one space

开发者 https://www.devze.com 2023-03-30 15:49 出处:网络
I need to find a regex that will match any string, at开发者_如何学JAVA least 6 characters long, including only one space, but the space can\'t be the first or the last character.

I need to find a regex that will match any string, at开发者_如何学JAVA least 6 characters long, including only one space, but the space can't be the first or the last character. I tried many combinations of \S and \s but I am now stuck. Any help?


Including one or zero spaces:

^(?=.{6,})(\S+\s?\S+)$

If you meant that it must have a space then you should remove the ? in \s?. This will only work in a regex engine that supports positive lookaheads and recognizes the \s and \S sequences. RegexPal


preg_match_all("/[^\s][.*]{6,}[^\s]/", $str, $matches);

0

精彩评论

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