2017-02-20 1 views
-2

내가 문자열이 있습니다preg_match() 수정 방법 : 알 수없는 수정 자 '{'?

$11,950 Some random string $415 

을 내가 정수로 처음 가격 정보를 분석 할 :

thouand 분리기와 첫 번째 숫자 부분을 얻기 위하여
11950 

, 내가 만든 정규식 :

[0-9]{1,3}(,[0-9]{3})*(\.[0-9]+)? 

online regex editor에서 예상대로 작동합니다.

는 그러나 나는 preg_match을 위해 그것을 사용하는 경우 : 내가 잘못 뭐하는 거지

preg_match(): Unknown modifier '{' 

php sandbox

:

$price = 0; 
$content = '$11,950 Some random string $415'; 
if (preg_match('[0-9]{1,3}(,[0-9]{3})*(\.[0-9]+)', $content, $matches)) {    
    var_dump($matches[0]); 
} 

내가 오류가? 이와 같이

+3

'는 preg_match ('/ [0-9] {1,3} ([0-9] {3}) * (\ [0-9] +)/', $ content, $ matches)' – anubhava

+1

[구분 기호] (http://php.net/manual/en/regexp.reference.delimiters.php)에 대해 읽어보십시오. –

답변

0

용도 :.

$regex = "/[0-9]{1,3}(,[0-9]{3})*(\.[0-9]+)/"; 
$content = '$11,950 Some random string $415'; 
    if (preg_match($regex, $content, $matches)) { 

     var_dump($matches[0]); 
    } else { 

     echo "The regex pattern does not match. :("; 
    } 
관련 문제