May I ask if PHP uses a regular expression?

Source: Internet
Author: User
May I ask if PHP uses a regular expression? The following two situations may occur in a project,

First:
... SADFA:

123

SLDKJLSKDFJ .........

Second:
... SADFA:
0

SLDKJLSKDFJ .........

Excuse me, can I use a regular expression to express it?
What I think:
Preg_match ("/SADFA :.*? (\ D +)/is ", $ text, $ reg );
In this way, we get the value 0 in javascript: void (0,
Change it to the following:
Preg_match ("/SADFA :.*? ([1-9] \ d *)/is ", $ text, $ reg );
I can get the number of the red part, but if the red part is 0, I can't help it. please help...


Reply to discussion (solution)

Use preg_match_all ()

Use preg_match_all ()

In the first case, I need a second number,
In the second case, I want to take the first number,

I want to use a regular expression. I don't know how to write it.

 

$ S = <TXT first :........ SADFA: 123SLDKJLSKDFJ ......... the second type :........ SADFA: 0SLDKJLSKDFJ ......... TXT; preg_match_all ('/SADFA :. + [> \ s] (\ d +) \ B/sU ', $ s, $ r); print_r ($ r );
Array
(
[0] => Array
(
[0] => SADFA:

123
[1] => SADFA:
0
)

[1] => Array
(
[0] = & gt; 123
[1] => 0
)

)

Thanks to the two above, they can solve the problem from different ideas,

Due to the huge data volume, I don't know if strip_tags will affect the efficiency or try again. thanks to baoxiaohua.

I personally prefer the xuzuning method, which is exactly what I want to find. I have never thought of it. thank you very much.

My final/SADFA :.*? [> \ S] (\ d +)/is, saving non-greedy match. I don't know if there will be any problems ..

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.