REGEX捕获欧元符号

时间:2015-09-21 09:08:40

标签: php regex preg-match

如何在Confirmation code: Payout: €66 x 7 Nights: €461 Airbnb Service Fee: -€17 Total Payout: €444 忽略所有数字

之后捕获任何内容
#include <iostream>

int main()
{
    int theInt = 1337;
    int & theReference = theInt;
    int * thePointer = &theInt;

    std::cout << "int: " << theInt << "\n";
    std::cout << "referenz: " << theReference << "\n";
    std::cout << "pointer: " << *thePointer << "\n";
    std::cout << "pointer: " << *thePointer << "\n";

    //std::cout << "foo" << "\n";

    return 0;
}

Live Example:

4 个答案:

答案 0 :(得分:0)

使用\K或lookbehind。

\bTotal Payout:\s*\K.+

答案 1 :(得分:0)

Total Payout:\s+\K\D+

您可以在此处使用\K

\K resets the starting point of the reported match. Any previously consumed characters are no longer included in the final match

参见演示。

https://regex101.com/r/gM6pO2/3

答案 2 :(得分:0)

您可以使用?<=

后面的样子

请参阅此模式(?<=Total Payout:)\s+(.*\d+)然后捕获该组。

查看演示https://regex101.com/r/gM6pO2/4

确认码:

<强>输入

Payout: 
€66 x 7 Nights: €461
Airbnb Service Fee: -€17
Total Payout: €444

<强>输出

€444

答案 3 :(得分:0)

您可以使用/.*(€\d+)/,即:

<?php
$string = <<< EOF
Confirmation code: 

Payout: 
€66 x 7 Nights: €461
Airbnb Service Fee: -€17
Total Payout: €444
EOF;

preg_match_all('/.*(€\d+)/si', $string, $matches, PREG_PATTERN_ORDER);
$totalPayout = $matches[1][0];
echo $totalPayout;
//€444

<强>样本:

http://ideone.com/gmS1uf

相关问题