정규표현식 모음

ElegantCoder::wiki();

정규표현식(PHP, preg_match()기준입니다)

  • 텍스트에서 img 태그만 잘라내기
/<\s*img[^>]*>/mi
  • 소스코드에서 주석 제거
#(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*)#
  • Lookaround를 이용해 숫자만 걸러내기
<td><table width='192' border='0' cellspacing='0' cellpadding='0'>

                    <tr height='27'>
                      <td width='27' align='center'background='http://img.kbstar.com/lot/main_num_bg.gif' class='lot_number'>02</td>
                      <td width='5'></td>
                      <td width='27' align='center'background='http://img.kbstar.com/lot/main_num_bg.gif' class='lot_number'>03</td>
                      <td width='5'></td>
                      <td width='27' align='center'background='http://img.kbstar.com/lot/main_num_bg.gif' class='lot_number'>04</td>
                      <td width='5'></td>
                      <td width='27' align='center'background='http://img.kbstar.com/lot/main_num_bg.gif' class='lot_number'>05</td>

                      <td width='5'></td>
                      <td width='27' align='center'background='http://img.kbstar.com/lot/main_num_bg.gif' class='lot_number'>20</td>
                      <td width='5'></td>
                      <td width='27' align='center'background='http://img.kbstar.com/lot/main_num_bg.gif' class='lot_number'>24</td>
                      <td width='5'></td>
                    </tr>
preg_match_all('/(?<=lot_number\'>)\d\d(?=<\/td>)/', $str, $matches);
array (
 0 =>
array (
0 => '02',
1 => '03',
2 => '04',
3 => '05',
4 => '20',
5 => '24',
),


)


개인 도구