How to get the regular expression string inverse

Source: Internet
Author: User
How does the regular expression string get reversed?
I have a URL rule as follows:

mm.[*|a|b|add].cn

Where A, B, add represents an exception

For example

Mm.a.cn cannot match

Mm.x.cn can match

How to write the regular???

All I know is mm\. [a|b|add]\.cn can match all exceptions, but I just want a reverse result?]
Regular Expressions Regular URL

Share to:


------Solution--------------------
$s 1= ' mm.a.cn ';
$s 2= ' mm.add.cn ';
$s 3= ' mm.c.cn ';
$p = '/mm\. (.+) (? ------Solution--------------------
B
------Solution--------------------
Add) \.cn/';
$bool 1=preg_match ($p, $s 1);
$bool 2=preg_match ($p, $s 2);
$bool 3=preg_match ($p, $s 3);
Var_dump ($bool 1, $bool 2, $bool 3);

int (0) int (0) int (1)
------Solution--------------------
Preg_match (' #www \. ( A
------Solution--------------------
B
------Solution--------------------
Add) \.cn# ', $str)


If it doesn't match.

!preg_match (' #www \. ( A
------Solution--------------------
B
------Solution--------------------
Add) \.cn# ', $str)

------Solution--------------------
Can only say to LZ-this is hard to write

References:
$s 1= ' mm.a.cn ';
$s 2= ' mm.add.cn ';
$s 3= ' mm.c.cn ';
$p = '/mm\. (.+) (? ------Solution--------------------
B
------Solution--------------------
Add) \.cn/';
$bool 1=preg_match ($p, $s 1);
$bool 2=preg_match ($p, $s 2);
$bool 3=preg_match ($p, $s 3);
Var_dump ($bool 1, $bool 2, $bool 3);

int (0) int (0) int (1)

Try mm.aadd.cn?
------Solution--------------------
$s =<<< TXT


mm.aadd.cn
mm.c.cn
TXT;

Preg_match_all ('/mm\. A
------Solution--------------------
B
------Solution--------------------
Add). *?\.cn/s ', $s, $r);
Print_r ($R);
Preg_match_all ('/mm\. A\.
------Solution--------------------
B\.
------Solution--------------------
Add\.). *?\.CN/S ', $s, $r);
Print_r ($R);
Array
(
[0] = = Array
(
[0] = mm.x.cn
[1] = mm.c.cn
)

)
Array
(
[0] = = Array
(
[0] = mm.x.cn
[1] = mm.aadd.cn
[2] = mm.c.cn
)

)

------Solution--------------------
Preg_match_all ('/mm\. A\.
------Solution--------------------
B\.
------Solution--------------------
Add\.). *?\.CN/S ', $s, $r);
Can write
Preg_match_all ('/mm\. (?: A
------Solution--------------------
B
------Solution--------------------
Add) \.). *?\.CN/S ', $s, $r);

------Solution--------------------
preg_match_all ('/mm\. A\.
------Solution--------------------
B\.
------Solution--------------------
add\.). *?\.CN/S ', $s, $r);
can write
Preg_match_all ('/mm\. (?: a
------solution--------------------
B
------Solution--------------------
Add) \.). *?\.CN/S ', $s, $r);
  • 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.