[英]Regular expression match pattern php
我有一個HTML字符串,想要提取特定標記<selection>
內的內容。
例:
Lorem Ipsum is simply <selection alt="dummy" name="dummy">dummy</selection > text the printing and typesetting <selection alt="industry" name="industry">industry</selection>. Lorem Ipsum has been the industry's <selection alt="standard" name="standard">standard</selection>dummy text ever since the 1500s.
在上面的HTML字符串中,我需要在selection
標簽中提取文本,但是所有標簽都具有不同的屬性。 請幫我解決。
嘗試這個:
preg_match_all('/<selection.*?">(.*?)<\/selection.*?>/is',$sourcestring,$matches);
$ matches是數組形式的結果。 希望對您有幫助。
您可以嘗試以下操作:
/<selection[^>]*>([^<]*)/g
http://regex101.com/r/pS3sM0/1
要在<selection>...</selection>
之間添加標簽:
/<selection[^>]*>(.*?)(?:<\/selection)/g
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.