Ask how to match a regular expression:
(.*)
Content:
Str
Title 1
Title 2
Target: (must contain
)
Title 2
Current error result: (The entire segment is matched)
Title 1Title 2
Reply to discussion (solution)
Add U to prohibit greed
Is that what it means?
$ Str ='
StrTitle 1Title 2
'; Preg_match_all ("/
(. *) <\/B> <\/p> <\/a>/is ", $ str, $ match); echo"
";print_r($match);
Is that what it means?
$ Str ='
StrTitle 1Title 2
'; Preg_match_all ("/
(. *) <\/B> <\/p> <\/a>/is ", $ str, $ match); echo"
";print_r($match);
Correct results:
Title 2
Current error result:
Title 1
Title 2
I tried this and matched the following results.
Preg_match_all ("/(. *) <\/B> <\/p> <\/a>/isU ", $ str, $ match); // add U to prohibit greedy mode.
Preg_match_all ("/(. *) <\/B> <\/p> <\/a>/isU ", $ str, $ match); // add U to prohibit greedy mode.
Damn csdn
Preg_match_all ("/(. *) <\/B> <\/p> <\/a>/is U ", $ str, $ match );
Add U to prohibit greed
It seems that it is not greedy because it immediately ends after matching the results.
Added U
$ Str ='
StrTitle 1Title 2
'; Preg_match_all ("/
(. *) <\/B> <\/p> <\/a>/U ", $ str, $ match); echo"
";print_r($match);
Result:
Array ([0] => Array ([0] => title 1Title 2
) [1] => Array ([0] => title 2 ))
Preg_match_all ("/(. *) <\/B> <\/p> <\/a>/isU ", $ str, $ match); // add U to prohibit greedy mode.
Damn csdn
Preg_match_all ("/(. *) <\/B> <\/p> <\/a>/is U ", $ str, $ match );
Result:
Array ([0] => Array ([0] => title 1Title 2
) [1] => Array ([0] => title 2 ))
The previous pile of this is redundant:
Title 1 Give a reminder
To match some boundary content, write regular expressions in the form of boundary + exclusive boundary + boundary to avoid random use of dots.
In particular, html and other markup languages. because the markup language is characterized by a tag, it is also legal to include a line break in the middle, and the dot cannot be covered. if you use a dot, it is a bit of an assumption that the source string must be neat.
For example:
Href ="
Abc/abc.html ">
ABC
This html string is completely legal and does not affect the display of the webpage at all, but the regular expression is required.
"[^"] *"
<[^>] +>
[^ <] *
$ S = <TXT
StrTitle 1Title 2
TXT; preg_match ('/. + ()/is', $ s, $ m); echo $ m [1];
Title 2
Simplify it.
Preg_match ('/. + ()/is', $ s, $ m); echo $ m [1];/*Title 2
*/