How to handle the syntax of a regular expression in PHP
Source: Internet
Author: User
Syntax for regular expressions in PHP
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
------to solve the idea----------------------
/\[font= "([^\"]+?) ". +?\](.*?) \[\/font\]/i
Give it a try
------to solve the idea----------------------
echo preg_replace ('/\[font= ' ([^\ "]+?)". *?\](.*?) \[\/font\]/i ', ' $1@@@@$2 ', ' [font= ', Microsoft Yahei '] People's Republic of China [/font] ');
------to solve the idea----------------------
[^\"]
[] 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 '
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service