2015-01-30
정규표현식이, 안쓰다 보면 까먹고, 예전에 잘 만들어놓은 정규표현식을 잊어버리기도 하고 해서(정말이지.. 완전 기초조차 잊어버리는 경우도 있다), 이곳엔 필자가 정규표현식을 쓸때마다 기록 하는 곳으로 쓸 예정이다.

$subject = "00:01-02:00";
$pattern = '/\d\d/';
preg_match_all($pattern, $subject, $matches);
print_r($matches);
Array
(
    [0] => Array
        (
            [0] => 00
            [1] => 01
            [2] => 02
            [3] => 00
        )

)


//------------------ 2015.02.02 추가
if( !preg_match('/jpeg|gif|pdf|bmp|png/i', $Ftype[1]) ) echo "no match!<br>"; //넘어온 파일의 확장자 검사
if( preg_match('/^DEFAULT|^'.$code.'/i', $tval['d']) ) echo "match!"; //해당 문자로 시작하는 배열요소인지 검사
no match!
match!


//------------------ 2015.03.06 추가
//공백을 제외한 것들만 배열 요소로 만드는 방법

$str = "   aa bb cc    dd ese  se    "; 
$matches = preg_split('/[\s]+/i', trim($str));

preg_match_all('/[^\s]+/',$str,$matches);

$matches = preg_split('/\s+/',$str,-1,1);

$matches = preg_split('/\s/',$str,-1,1);

while ( strpos($str,'  ')!==false ) $str = str_replace('  ',' ',$str); 
$str = trim($str);
$matches = explode(' ',$str);
print_r($matches);
Array
(
    [0] => aa
    [1] => bb
    [2] => cc
    [3] => dd
    [4] => ese
    [5] => se
)


//------------------ 2015.09.30 추가
//<html></html>에 있는 값들만 가져오기

$str = "efeavadvq3rvae<html> aaaaaaaaaaaaaa<br><html></html>aaaaaaaaa><>
LPML:OP?';ojao;dsfnewwklvZ< 2>sd;oqm<html><body>eeeeeeee</body></html>dasdofio;2u34211j45390568401233721-!@#$!@#$%^%^#&^$*&^$~!@ 
23$!@423<html>adfgdsgfsgfsd2015-09-30</html>asdfawee";

preg_match_all("/<html>(.*)<\/html>/", $str, $arr);

print_r( $arr );
Array
(
    [0] => Array
        (
            [0] => <html> aaaaaaaaaaaaaa<br><html></html>
            [1] => <html><body>eeeeeeee</body></html>
            [2] => <html>adfgdsgfsgfsd2015-09-30</html>
        )

    [1] => Array
        (
            [0] =>  aaaaaaaaaaaaaa<br><html>
            [1] => <body>eeeeeeee</body>
            [2] => adfgdsgfsgfsd2015-09-30
        )

)


//------------------ 2017.07.26 추가
/^((?!https?:\/\/)[\s\S])*$/g
http:// or https:// 가 포함되면 false