Regular expression: Difference between revisions

Jump to navigation Jump to search
594 bytes removed ,  20 September 2016
Line 473: Line 473:


=== 尋找 Hashtag ===
=== 尋找 Hashtag ===
什麼是 [https://zh.wikipedia.org/wiki/%E4%B8%BB%E9%A1%8C%E6%A8%99%E7%B1%A4 主題標籤] (Hashtag)
[[Extract all hashtags from text]]
* 因為連結包含 # 符號,所以需要事先處理。
* PHP code<ref>[http://stackoverflow.com/questions/3060601/retrieve-all-hashtags-from-a-tweet-in-a-php-function regex - Retrieve all hashtags from a tweet in a PHP function - Stack Overflow]</ref>:
<pre>
preg_match_all("/(#[^\s|\-|,|\"|,|\[|\]|『|』|/|~|(|)|(|)|【|】|《|》|-|「|」|!|!|、|?|:|…|:|#|\.|.|。|?]+)/ui", $string, $matches);
</pre>
* 還需要處理以下狀況
<pre>
illegal
#12345
#___
#_
#__123
 
legal
#1_abc
#_abc
</pre>


== Search unmatched string ==
== Search unmatched string ==

Navigation menu