How to deal with non-matching items in PHP regular expression processing

Source: Internet
Author: User
Tags php regular expression
PHP regular expression processing non-matching items, for example ;?...? & Gt; code other than tag. For example, enclose curly braces. The requirement is to put the following code: aaa & lt ;?...? & Gt; bbb & lt ;?...? & Gt; ccc must be processed as follows: {aaa} & lt ;?...? & Gt; {bbb} & lt ;?...? & Gt; {ccc} Note & lt ;?...? & Gt; intermediate content and & lt ;?...? & Gt; other content are PHP regular expressions for non-matching items
For example Code other than the tag. For example, enclose curly braces.

The following code is required:
Aaa Bbb Ccc
To process it like this:
{Aaa} {Bbb} {Ccc}

Note: Intermediate content and Other content is not fixed.
What we need to deal with IS Something outside. Which are aaa, bbb, and ccc.

------ Solution --------------------
$ A = array ('/(.) <\? /','/\?> (.)/');
$ B = array ('$1} {$1 ');
Echo $ c = preg_replace ($ a, $ B, '{'. $ str .'}');

Test it by yourself
------ Solution --------------------
$ S = "aaa Bbb Ccc ";
Echo preg_replace ("/(^ | \?>) (. +) (<\? | $)/IU "," \ 1 {\ 2} \ 3 ", $ s );


{Aaa} {Bbb} {Ccc}

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.