[英]How to replace all occurrences of a character except the first one in PHP using a regular expression?
[英]Extract all occurrences of a pattern using regular expression and php
我想從字符串中提取出現在'ob'
和','
之間'ob'
所有單詞
' QS=TCE,Ob=Web technology,OB=Product SPe,OB=Dev profile,OB=Computer Management,oB=Hardware Services,cd=sti,CD=com,cd=ws'
我想要以下結果:
Web technology,Product SPe,Dev profile,Computer Management,Hardware Services
我試過的是:
preg_match_all("!\OB=(\w+)\,!", ' QS=TCE,Ob=Web technology,OB=Product SPe,OB=Dev profile,OB=Computer Management,oB=Hardware Services,cd=sti,CD=com,cd=ws', $matches);
print_r($matches);
但這沒有任何結果。 這有什么問題?
您需要考慮單詞之間的空格,在這里我將使用否定。 另外,您需要刪除“ O”和逗號前面的轉義序列,並打開i
(不區分大小寫)模式修飾符。
preg_match_all('!OB=([^,]+),!i', $str, $matches);
print_r($matches[1]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.