A regular problem.

Source: Internet
Author: User
$string = ' dj%a3%a3999 '; if (Preg_match ('/^[dj]{2} ([(\%23) (\%A3\%A3)]) ((\w) +) $/i ', $string, $result)) {Print_r ($ result);}

No match, there is no good solution.


Reply to discussion (solution)

You'd better talk about your needs, the middle part of it is very messy to see you.

/* Demand is DJ a grouping%a3%a3 or%23 is another grouping 999 is a grouping that gets the corresponding data by $result. such as: */$result [0]= ' DJ '; $result [1]= '%a3%a3 '; $result [2]= ' 999 ';

$s = ' dj%a3%a3999 ';p reg_match ('/([^%]+) ((?:%a3|23) +) (. +)/', $s, $r);p Rint_r ($r);
Array ([0] = dj%a3%a3999 [1] = DJ [2] =%A3%A3 [3] = 999)

Used this:

$string = ' dj%a3%a3999 '; if (Preg_match ('/^ ([dj]{2}) ([%a3]+] (\d{3}) $/i ', $string, $result)) {Print_r ($result);}


Results:
Array ([0] = dj%a3%a3999 [1] = DJ [2] =%A3%A3 [3] = 999)

$s = ' dj%a3%a3999 ';p reg_match ('/([^%]+) ((?:%a3|23) +) (. +)/', $s, $r);p Rint_r ($r);
Array ([0] = dj%a3%a3999 [1] = DJ [2] =%A3%A3 [3] = 999)

If $s = ' dj%23999 ';

Used this:

$string = ' dj%a3%a3999 '; if (Preg_match ('/^ ([dj]{2}) ([%a3]+] (\d{3}) $/i ', $string, $result)) {Print_r ($result);}

[/code]
This string also needs to match: $string = ' dj%23999 ';

$s = ' dj%23999 ';
Preg_match ('/([^%]+) ((?:% (?: a3|23)) +) (. +)/', $s, $r);
Or
Preg_match ('/([^%]+) ((?:%a3|%23) +) (. +)/', $s, $r);

The regular expression Rule description has:
| If there is ambiguity in the operation, it needs to be listed individually or enclosed in parentheses.

Obviously (?:%a3|23)% was incorporated into the A3 so that there was ambiguity

Boss, can you help me explain, I see there are a lot of regular front plus?: I want to know what this means?

(?:...) Same as group (...), but results do not appear in result set

(?:...) Same as group (...), but results do not appear in result set

Boss, can you help me match an address, such as:

Www.sohu.com,www.baidu.com,www.yahoo.com.n

This connects to a maximum of 9 URLs, which can also match sohu.com,baidu.com,yahoo.com.cn

(?! (W)) (\w+ (-\w+) *) (\. (\w+ (-\w+) *)) *

  • Related Article

    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.