PHP regular match backslash '\' and dollar '$', php slash

Source: Internet
Author: User
Tags php regular expression

PHP regular match backslash '\' and dollar '$', php slash

This example describes the PHP Regular Expression matching method with the backslash '\' and dollar '$. We will share this with you for your reference. The details are as follows:

1. test. php:

<? Php $ content = '2017 <td> 1111111 <\/td> 3 $ '; // '\\\\\\/'100' \ 'escape string 100 '\', the string is '\' // 3rd ''\ 'to escape 4th'' \', which is equivalent to the string '\' // 5th ''\ 'to escape 4th '/', equivalent to the string '/' // character combination as '\/' Two '\' regular expressions as '\' $ pattern = '/<td> ([0-9] {7 ,}) <\\\\\/td> \ d \\$ $/'; $ result = preg_match_all ($ pattern, $ content, $ match_result); if ($ result) print_r ($ match_result); else echo ("not match ");

2. Method 2:

$content = '1111111<td>2222222<\/td>3$';$pattern = "!<td>(\d{7,})<\Q\/\Etd>\d\Q$\E!";$result = preg_match_all($pattern, $content, $m);if($result)  print_r($m);else  echo("not match");

3. Running result:

Array(  [0] => Array    (      [0] => <td>2222222<\/td>3$    )  [1] => Array    (      [0] => 2222222    ))

PS: here we will provide two very convenient Regular Expression tools for your reference:

JavaScript Regular Expression online testing tool:
Http://tools.jb51.net/regex/javascript

Regular Expression generation tool:
Http://tools.jb51.net/regex/create_reg

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.