ȸ¿ø·Î±×ÀÎ
2³â Àü
Á¤±ÔÇ¥Çö½Ä¿¡ ¸Â´Â °ÍÀ» ¸ðµÎ ÃßÃâÇÏ´Â PHP ÇÔ¼ö
ÆÐÅÏ¿¡ Å«µû¿ÈÇ¥( " ) »ç¿ë½Ã ¹é½½·¡½Ã°¡ Çϳª ´õ ÇÊ¿äÇÏ´Ù.
¿¹½Ã 1
¸ðµç ÅÂ±× ÃßÃâ
preg_match_all("/(<([\w]+)[^>]*>)(.*?)(<\/\\2>)/", $html, $matches);
¸ðµç a ÅÂ±× ÃßÃâ
preg_match_all("/(<(a+)[^>]*>)(.*?)(<\/\\2>)/", $html, $matches);
¸ðµç ¸ÆÁÖ¼Ò ÃßÃâ
preg_match_all("/([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}/", $text, $matches);
¿¹½Ã 2: URL ÃßÃâ
http://, https://·Î ½ÃÀÛÇÏ´Â URL ¼öÁý
preg_match_all("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $html, $matches);
//, http://, https://·Î ½ÃÀÛÇÏ´Â URL ¼öÁý
preg_match_all("/(\b(?:(?:https?|ftp):))?\/\/[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $text, $matches);
preg_match_all() Çѱ۴ܾî ÃßÃâ
$text = "pattern¿¡ ÁÖ¾îÁø Á¤±Ô Ç¥Çö½ÄÀ¸·Î subject¿¡¼ ¸ðµç ¸ÅÄ¡¸¦ ã¾Æ³»°í,
flags¿¡ ÁöÁ¤ÇÑ ¹æ¹ý¿¡ µû¶ó¼ matches¿¡ ³Ö½À´Ï´Ù.
óÀ½ ¸ÅÄ¡°¡ ¹ß°ßµÈ ÈÄ, ÀÌÈÄ °Ë»öÀº ¸¶Áö¸· ¸ÅÄ¡ÀÇ ³¡¿¡¼ºÎÅÍ ÀÌ·ç¾îÁý´Ï´Ù.";
preg_match_all("|(?<hangul>[°¡-힣]+)|u", $text, $out);
print_r( $out['hangul'] );
Array
(
[0] => ¿¡
[1] => ÁÖ¾îÁø
[2] => Á¤±Ô
[3] => Ç¥Çö½ÄÀ¸·Î
[4] => ¿¡¼
[5] => ¸ðµç
[6] => ¸ÅÄ¡¸¦
[7] => ã¾Æ³»°í
[8] => ¿¡
[9] => ÁöÁ¤ÇÑ
[10] => ¹æ¹ý¿¡
[11] => µû¶ó¼
[12] => ¿¡
[13] => ³Ö½À´Ï´Ù
[14] => óÀ½
[15] => ¸ÅÄ¡°¡
[16] => ¹ß°ßµÈ
[17] => ÈÄ
[18] => ÀÌÈÄ
[19] => °Ë»öÀº
[20] => ¸¶Áö¸·
[21] => ¸ÅÄ¡ÀÇ
[22] => ³¡¿¡¼ºÎÅÍ
[23] => ÀÌ·ç¾îÁý´Ï´Ù
)
$text = "apple
»ç°ú
pear
banana
ÃÊÄÚbanana
¹Ù³ª³ª
»ç°ú";
preg_match_all("|(?<hangul>[°¡-힣]+)|su", $text, $out);
print_r( $out['hangul'] );
Array
(
[0] => »ç°ú
[1] => ÃÊÄÚ
[2] => ¹Ù³ª³ª
[3] => »ç°ú
)
preg match all() ¿µ¾î´Ü¾î ÃßÃâ
$str = "Charles Robert Darwin, FRS (12 February 1809 – 19 April 1882) was an English naturalist. He established that all species of life have descended over time from common ancestors, and proposed the scientific theory that this branching pattern of evolution resulted from a process that he called natural selection, in which the struggle for existence has a similar effect to the artificial selection involved in selective breeding.";
preg_match_all('/([a-zA-Z]|\xC3[\x80-\x96\x98-\xB6\xB8-\xBF]|\xC5[\x92\x93\xA0\xA1\xB8\xBD\xBE]){4,}/', $str, $match_arr);
$words = $match_arr[0];
print_r($words);
Array
(
[0] => Charles
[1] => Robert
[2] => Darwin
[3] => February
[4] => April
[5] => English
[6] => naturalist
[7] => established
[8] => that
[9] => species
[10] => life
[11] => have
[12] => descended
[13] => over
[14] => time
[15] => from
[16] => common
[17] => ancestors
[18] => proposed
[19] => scientific
[20] => theory
[21] => that
[22] => this
[23] => branching
[24] => pattern
[25] => evolution
[26] => resulted
[27] => from
[28] => process
[29] => that
[30] => called
[31] => natural
[32] => selection
[33] => which
[34] => struggle
[35] => existence
[36] => similar
[37] => effect
[38] => artificial
[39] => selection
[40] => involved
[41] => selective
[42] => breeding
)
preg match all() ¸ÆÁÖ¼Ò ÃßÃâ
¿¹½Ã 1
function extract_mac_address($str) {
preg_match_all("/([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}/", $str, $matches);
return $matches[0];
}
$ifconfig_result = "eth0 Link encap:Ethernet HWaddr 52:54:00:5D:DB:01
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:982 errors:0 dropped:0 overruns:0 frame:0
TX packets:970 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:92188 (90.0 KiB) TX bytes:91468 (89.3 KiB)
eth1 Link encap:Ethernet HWaddr 52:54:00:5D:DB:02
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:982 errors:0 dropped:0 overruns:0 frame:0
TX packets:970 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:92188 (90.0 KiB) TX bytes:91468 (89.3 KiB)";
$mac_addr_arr = extract_mac_address( $ifconfig_result );
print_r( $mac_addr_arr );
Array
(
[0] => 52:54:00:5D:DB:01
[1] => 52:54:00:5D:DB:02
)
¿¹½Ã 2
function extract_mac_address($str) {
preg_match_all("/([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}/", $str, $matches);
return $matches[0];
}
exec("ifconfig", $output);
$ifconfig_result = implode("\n", $output);
$mac_addr_arr = extract_mac_address( $ifconfig_result );
print_r( $mac_addr_arr );
# Array
# (
# [0] => 68:0A:24:79:1C:35
# )
Á¤±ÔÇ¥Çö½Ä ¿¹½Ã
ÀüȹøÈ£
^d{3}\-d{4}\-d{4}$
¿¹: 012-3456-7890, 123-4567-8901
^d{2,3}\-d{3,4}\-d{4}$
¿¹: 02-1234-5678, 031-234-5678, 123-456-7890
^01(?:0|1[6-9])\-(?:d{3}|d{4})\-d{4}$
À̸ÞÀÏ ÁÖ¼Ò
^[0-9a-zA-Z_\-]+@[.0-9a-zA-Z_\-]+$
^[0-9a-zA-Z_\-]+@[0-9a-zA-Z_-]+(\.[0-9a-zA-Z_\-]+)*$
^[0-9a-zA-Z_\-]+@[0-9a-zA-Z_\-]+(\.[0-9a-zA-Z_\-]+){1,2}$
Java
\\w+@\\w+\\W\\w+
IP ÁÖ¼Ò
^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$
0.0.0.0 ~ 999.999.999.999
¸Æ ÁÖ¼Ò
^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$
Áֹεî·Ï¹øÈ£
^\d{6}\-[1-4]\d{6}$
ű×
<textarea ¡¦ >ºÎÅÍ </textarea>±îÁö
<textarea\b[^>]*>(.*?)</textarea>
ÇÑÀÚ
[\x4E00-\x9FA5]|[\xF900-\xFA2D]
[\x{4E00}-\x{9FA5}]|[\x{F900}-\x{FA2D}]
´Ù±¹¾î
È÷¶ó°¡³ª [\x{3041}-\x{309e}] / [-ゟ]
Àü°¢ °¡Å¸Ä«³ª [\x{309b}-\x{309c}\x{30a1}-\x{30fe}] / [゠-ヿ]
¹Ý°¢ °¡³ª [\x{ff61}-\x{ff9f}]
CJK Ç¥Àǹ®ÀÚ [\x{3400}-\x{9fff}\x{f900}-\x{fa2d}]
Èùµð¾î [\x{0900}-\x{097F}]
·¯½Ã¾Æ¾î [\x{0410}-\x{044F}\x{0500}-\x{052F}\x{0400}-\x{04FF}]
¸ðµç ÇѱÛ(ÀÚ¼Ò) ã±â1 [\x{3131}-\x{318E}]|[\x{AC00}-\x{D7A3}]
¸ðµç ÇѱÛ(ÀÚ¼Ò) ã±â2 [\x{1100}-\x{11f9}\x{3131}-\x{318e}\x{ac00}-\x{d7a3}]
ű¹¾î [กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำิีึืฺุู฿เแโใไๅๆ็่้๊๋์ํ๎๏๐๑๒๓๔๕๖๗๘๙๚๛]
ÀϺ» ÃâÆÇ»ç À̸§ ³¡¹®ÀÚ (üå|Þä|ßöïÁ|ßöÛ®|ßöêÂ|ÓÑ|ÓÞùÊ|ÙþÍ·|á¶|ν|õó÷ú|ÊÈ|ÏÑ|ÙþÍ·|Þì)
±³Ã¼
HTML ÁÖ¼® Á¦°Å
<!--ºÎÅÍ -->±îÁö(ÁÙ¹Ù²Þ Æ÷ÇÔ)¸¦ ºó¹®ÀÚ¿·Î ±³Ã¼
<!--(.|\n|\r)*-->
ÁÙ¹Ù²Þ 2°³¸¦ 1°³·Î ±³Ã¼
\n\s*\n
\n
̵̧ : 117
̵̧
¸ñ·Ï