How to obtain the reverse expression of a regular expression string?

Source: Internet
Author: User
How to obtain the reverse expression of a regular expression string? Regular expression regular url

I have a url rule as follows:

Mm. [* | a | B | add]. cn

Where a, B, and add indicate exceptions

For example

Mm.a.cn does not match

Mm.x.cn can be matched

How to write regular expressions ???

I only know that mm \. [a | B | add] \. cn can match all the exceptions, but I just want an inverse result?


Reply to discussion (solution)

$ S1 = 'Mm .a.cn '; $ s2 = 'Mm .add.cn'; $ s3 = 'Mm .c.cn '; $ p ='/mm \. (. + )(?
   
Int (0) int (0) int (1)

preg_match('#www\.(a|b|add)\.cn#',$str)


Otherwise

!preg_match('#www\.(a|b|add)\.cn#',$str)

Can only be said to LZ ?? This regular expression is hard to write.

$ S1 = 'Mm .a.cn '; $ s2 = 'Mm .add.cn'; $ s3 = 'Mm .c.cn '; $ p ='/mm \. (. + )(?
    
Int (0) int (0) int (1)
Try mm.aadd.cn?

$s =<<< TXTmm.a.cn mm.x.cn mm.aadd.cnmm.c.cnTXT;preg_match_all('/mm\.(?!a|b|add).*?\.cn/s', $s, $r);print_r($r);preg_match_all('/mm\.(?!a\.|b\.|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
)

)

Preg_match_all ('/mm \.(?! A \. | B \. | add \.).*? \. Cn/S', $ s, $ r );
Writeable
Preg_match_all ('/mm \.(?! (? : A | B | add )\.).*? \. Cn/S', $ s, $ r );

Preg_match_all ('/mm \.(?! A \. | B \. | add \.).*? \. Cn/S', $ s, $ r );
Writeable
Preg_match_all ('/mm \.(?! (? : A | B | add )\.).*? \. Cn/S', $ s, $ r );
Add the last character as the exclusion object? Taught

The fourth floor should be okay. paste it first.

I accidentally saw this post ..
First .. I don't understand PHP. as a regular expression, isn't it very easy ..
Exclude the characters from the negative sense:
^ Mm \. [^ AB (? : Add)] + \. cn $
[^ AB (? : Add)] --> exclude a B add

Preg_match_all ('/mm \.(?! A \. | B \. | add \.).*? \. Cn/S', $ s, $ r );
Writeable
Preg_match_all ('/mm \.(?! (? : A | B | add )\.).*? \. Cn/S', $ s, $ r );

Is this writing redundant ~

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.