There are several possibilities for the original:
[font= "Microsoft Yahei" onclick= "alert (' B ')"] People's Republic of China [/font]
[font= "abc" onclick= "Alert (' B ')"] People's Republic of China [/font]
[font= "Microsoft Yahei"] People's Republic of China [/font]
[Font=abc onclick= "alert (' B ')"] People's Republic of China [/font]
[FONT=ABC] People's Republic of China [/font]
I want to do this, I only take out the characters after the font=, but not the onclick (not necessarily the onclick, there may be onfocus and the like) the following characters and the People's Republic of China.
This means that only the font name can be taken out, and the font name may contain quotation marks, but if there are characters behind the font, it is not taken.
The wording of the regular expression is asked.
When I write this, I will take the onclick and the following characters.
/\[font= (. *?) \](.*?) \[\/font\]/i
Reply to discussion (solution)
/\[font= "([^\"]+?) ". +?\](.*?) \[\/font\]/i
Give it a try
/\[font= "([^\"]+?) ". +?\](.*?) \[\/font\]/i
Give it a try
echo preg_replace ('/\[font= ' ([^\ "]+?)". +?\](.*?) \[\/font\]/i ', ' $1@@@@$2 ', ' [font= ', Microsoft Yahei '] People's Republic of China [/font] ');
I tried it, I can't.
echo preg_replace ('/\[font= ' ([^\ "]+?)". *?\](.*?) \[\/font\]/i ', ' $1@@@@$2 ', ' [font= ', Microsoft Yahei '] People's Republic of China [/font] ');
echo preg_replace ('/\[font= ' ([^\ "]+?)". *?\](.*?) \[\/font\]/i ', ' $1@@@@$2 ', ' [font= ', Microsoft Yahei '] People's Republic of China [/font] ');
OK. Thank you.
Excuse me: [^\] What does this string of characters stand for?
In addition, there is a situation that does not match is
[Font=microsoft] People's Republic of China [/font]
This is the one with no quotes on either side of the font. I tried it myself and didn't succeed. Please look again. Thank you.
[^\"]
[] Inside is a set of
^ is anything but what?
It means that any character except the double quotation mark matches, \ is escaped, in fact, can not
---------------------------------------------------------------------------------
[Font=microsoft] People's Republic of China [/font]
'/\[font= ' * ([^\ "]+)" *.*?\ "(. *?) \[\/font\]/i '
Ox break
Thank you for your help. Knot posts