[Solved] php Regular Expression Problem

Source: Internet
Author: User
[Resolved] {code ...} for multi-language websites, You need to extract $299.00, of which $ is uncertain, because there may be symbols such as $, £, and so on. It can be determined that there is a space before $299.00, after the decimal point... [resolved]

echo '
  ';$pa = '%

(.*?)

%sim';preg_match($pa, trim($message), $arr);if(strpos("Welcome back",$message)){ preg_match('/.\d{1,}.\d{1,2}/', $arr[1], $arr);}else{ preg_match('/.\d{1,}.\d{1,2}/', $arr[1], $arr);}echo($arr[0]);

========================================================== ======================================

For multi-language websites, You need to extract $299.00, of which $ is uncertain because it may be $, £, and other symbols,

It can be determined that $299.00 contains a space, and there are two digits after the decimal point,

In other words:

Your account has an unpaid bill amount of $299.00. Please complete the payment as soon as possible.

Or

Your account has an outstanding balance of $299.00. Please make a payment at your earliest convenience.

Extracted to $299.00.

Chinese display:

× Welcome back, Tao!

Your account has an unpaid bill amount of $299.00. Please complete the payment as soon as possible.

Make payment

× Welcome back, Tao!

Your account has an outstanding balance of $299.00. Please make a payment at your earliest convenience.

Make Payment

Reply content:

[Resolved]

echo '
  ';$pa = '%

(.*?)

%sim';preg_match($pa, trim($message), $arr);if(strpos("Welcome back",$message)){ preg_match('/.\d{1,}.\d{1,2}/', $arr[1], $arr);}else{ preg_match('/.\d{1,}.\d{1,2}/', $arr[1], $arr);}echo($arr[0]);

========================================================== ======================================

For multi-language websites, You need to extract $299.00, of which $ is uncertain because it may be $, £, and other symbols,

It can be determined that $299.00 contains a space, and there are two digits after the decimal point,

In other words:

Your account has an unpaid bill amount of $299.00. Please complete the payment as soon as possible.

Or

Your account has an outstanding balance of $299.00. Please make a payment at your earliest convenience.

Extracted to $299.00.

Chinese display:

× Welcome back, Tao!

Your account has an unpaid bill amount of $299.00. Please complete the payment as soon as possible.

Make payment

× Welcome back, Tao!

Your account has an outstanding balance of $299.00. Please make a payment at your earliest convenience.

Make Payment

From the code point of view, the content of this code should not change except the name and amount, so it is easier to do.
Directly go to the matching amount/\ s (. \ d + \. \ d {2})/g. The premise is that for this section of code, if it is the entire page, you need to restrict the matching to this section of code ..

Resolved:

echo '
  ';$pa = '%

(.*?)

%sim';preg_match($pa, trim($message), $arr);if(strpos("Welcome back",$message)){ preg_match('/.\d{1,}.\d{1,2}/', $arr[1], $arr);}else{ preg_match('/.\d{1,}.\d{1,2}/', $arr[1], $arr);}echo($arr[0]);

I don't know the subject's purpose. What is the purpose of extracting this amount? Is it necessary to make a payment? Should I go to the server to verify the payment? After all, this price front end can be tampered.

If you only need to match, you can use this expression.

$ Pattern = '# ([\ $ | ¥ | £1-9] [0-9] *. [0-9] {2}) # '; // $ subject =' Your account has an unpaid bill amount of $299.00. Please complete the payment as soon as possible. '; $ Subject = 'your account has an outstanding balance of $299.00. please make a payment at your earliest convenience. '; preg_match ($ pattern, $ subject, $ a); var_dump ($ a); // output: array (2) {[0] => string (7) "$299.00" [1] => string (7) "$299.00 "}

I don't know why it turned into two? Unknown reason

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.