ȸ¿ø°¡ÀԡžÆÀ̵ð/ºñ¹øã±â
ȨÀ¸·Î


PHP preg match all()
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 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
2,891
ÀÔ·Â Çʵ忡¼­ ƯÁ¤´Ü¾î(¿¹:#err)°¡ Æ÷ÇԵǾúÀ» ¶§ ½Ç½Ã°£ °¨Áö ¹× °æ°íâ ¶ç¿ì±â
2,890
µ¥ÀÌÅͺ£À̽º ÃÖÀûÈ­¿Í Äõ¸® È¿À²¼ºÀ» ³ôÀÌ °Ë»ö ¼º´ÉÀ» °³¼±ÇÏ´Â ¹æ¹ý
2,889
°£´ÜÇÑ °Ô½ÃÆÇ ¸¸µé±â
2,888
PHPÀÇ php.ini ÆÄÀÏ¿¡¼­ ¼³Á¤ÇÒ ¼ö ÀÖ´Â ÁÖ¿ä Ç׸ñµéÀ» Ä«Å×°í¸®º°·Î Á¤¸®
2,887
À¯Æ©ºê µ¿¿µ»óÀÇ ½æ³×ÀÏ À̹ÌÁö¸¦ üũÇÏ¿© À¯È¿ÇÑ ¿µ»óÀ̾ƴҶ§ ¿¬°áµÈ üũ¹Ú½º¸¦ ÀÚµ¿À¸·Î üũ
2,886
À̹ÌÁö URLÀÌ À¯È¿ÇÏÁö ¾ÊÀ» ¶§, ÇØ´ç À̹ÌÁö¿Í ¿¬°áµÈ üũ¹Ú½º¸¦ ÀÚµ¿À¸·Î üũ
2,885
HTTPS·Î Á¢¼ÓÇÑ »ç¿ëÀÚ¸¦ °­Á¦·Î HTTP·Î ¸®µð·º¼Ç ÇÏ·Á¸é
2,884
PHP¿¡¼­ MP3 ÆÄÀÏÀ» Á÷Á¢ ÀÐ°í ½ºÆ®¸®¹Ö Çϱâ
2,883
ÇöÀç ÆäÀÌÁö°¡ location.reload()¿¡ ÀÇÇØ »õ·Î°íħµÇ¾ú´ÂÁö
2,882
ÅؽºÆ® ÆÄÀÏÀ» Àаí, °¢ ÁÙÀÇ ³¡¿¡¼­ 6±ÛÀÚ¸¦ »èÁ¦ÇÑ ÈÄ, °á°ú¸¦ »õ·Î¿î ÆÄÀÏ¿¡ ÀúÀåÇÕ´Ï´Ù.
2,881
cURLÀ» »ç¿ëÇÏ¿© ¸®´ÙÀÌ·ºÆ®¸¦ µû¶ó°¡ ÃÖÁ¾ URL °¡Á®¿À±â
2,880
[PHP] $_SERVER ȯ°æº¯¼ö
2,879
10Áø¼ö <-> 16Áø¼ö º¯È¯±â PHP¼Ò½º
2,878
ÅؽºÆ®¿¡ Á÷Á¢ ±×¶óµ¥ÀÌ¼Ç »ö»óÀ» Àû¿ëÇÏ·Á¸é?
2,877
CSS¸¦ »ç¿ëÇÏ¿© ¿ä¼ÒÀÇ ³»¿ë¹°¿¡ µû¶ó width¸¦ Á¶Á¤ÇÏ´Â ¹æ¹ý
2,876
À¥¼­¹ö ip È®ÀÎ
2,875
À¥È£½ºÆÃÀÇ Àý´ë°æ·Î¸¦ È®ÀÎ
2,874
input ÀÔ·Â ÇÊµå ¾ÕµÚ °ø¹é ½Ç½Ã°£ Á¦°Å
2,873
Placeholder Æ÷Ä¿½º½Ã °¨Ãß±â
2,872
MySQL Áߺ¹µÈ µ¥ÀÌÅ͸¦ »èÁ¦
2,871
MySQL Áߺ¹ µ¥ÀÌÅÍ È®ÀÎ
2,870
sessionStorage.getItem ¿Í sessionStorage.setItem
2,869
Á¦ÀÌÄõ¸® ·£´ýÀ¸·Î ¹è°æ»ö º¯°æ
2,868
preg match¿¡ °üÇÑ Á¤±Ô½Ä
2,867
Stream an audio file with MediaPlayer ¿Àµð¿À ÆÄÀÏ ½ºÆ®¸®¹Ö Çϱâ
2,866
Audio Streaming PHP Code
2,865
PHP $ SERVER ȯ°æ º¯¼ö Á¤¸®
2,864
Vimeo (ºñ¸Þ¿À) API ¸¦ »ç¿ëÇÏ¿© Ç÷¹À̾î ÄÁÆ®·ÑÇϱâ
2,863
iframe »ç¿ë½Ã ÇÏ´Ü¿¡ ¹ß»ýÇÏ´Â °ø¹é Á¦°Å¹æ¹ý
2,862
¾ÆÀÌÇÁ·¹ÀÓ(iframe) Àüüȭ¸é °¡´ÉÇÏ°Ô Çϱâ
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.