문제

Regex:([a-zA-Z0-9]+)@((?1))

Test string: abc def@abc

result:

Match 1: def
Match 2: abc

How to allow spaces in regex?
I want the result to be:

Match 1: abc def
Match 2: abc
도움이 되었습니까?

해결책

You want to add the space character inside your character class [] in order to be matched also.

$text = 'abc def@abc';

preg_match_all('/[a-z0-9 ]+/i', $text, $matches);
print_r($matches[0]);

Output

Array
(
    [0] => abc def
    [1] => abc
)

다른 팁

try

preg_match("/^([a-zA-Z0-9 ])+$/i", $str)

want @ also match try

preg_match("/^([a-zA-Z0-9@ ])+$/i", $str) (i haven't test this)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top