Hello world
I have some problem with regex i want to get some parts of the string
Example 1: here i want to get the amount "1234.0" and the date "21-Jun-2021" also the mb number "20010598278"
21-Jun-2021 Bank Fees - Funds Transfer - MB #20010598278 ,Transfer ref.250922020633209684 Transferref.250333020633209684 1234.0 143,956.43
Example 2: here i want to get the amount "4444.0" and the date "25-Jun-2022" also the mb number "20010598278"
25-Jun-2022 Funds Transfer - MB # 20010598278,Transferref.250922020633209684 Transferref.250922020633209684 4444.0 143,966.43
the compelete text is
25-Jun-2022 Bankak Fees - Funds Transfer - MB #20010598278 ,Transfer ref.250922020633209684 Transferref.250922020633209684 10.0 143,956.43 25-Jun-2022 Funds Transfer - MB # 20010598278,Transferref.250922020633209684 Transferref.250922020633209684 4000.0 143,966.43 24-Jun-2022 Bankak Fees - BP #20278550446 , Transferref.#Bashaer 897906 Transfer ref.#Bashaer 897906 10.0 147,966.43 24-Jun-2022 BP # 20278550446,Transfer ref.#Bashaer 897906Transfer ref.#Bashaer 897906 20000.0 147,976.43 23-Jun-2022 Bankak Fees - -Zain #20277797569 , Transfer ref.#ZainBill 900946824 Transfer ref.#Zain Bill 900946824 10.0 167,976.43 23-Jun-2022 -Zain # 20277797569,Transfer ref.#Zain Bill 900946824Transfer ref.#Zain Bill 900946824 86700.0 167,986.43 23-Jun-2022 Funds Transfer - MB # 20010564267,Transferref.235022180616750305 Transferref.235022180616750305 10000.0 254,686.43 23-Jun-2022 Bankak Fees - Funds Transfer - MB #20010563561 ,Transfer ref.23302218068730100006 Transferref.23302218068730100006 10.0 244,686.43 23-Jun-2022 Funds Transfer - MB # 20010563561,Transferref.23302218068730100006 Transferref.23302218068730100006 3325.0 244,696.43 23-Jun-2022 Bankak Fees - Funds Transfer - MB #20010563116 ,Transfer ref.232022180646120606 Transferref.232022180646120606 10.0 248,021.43 23-Jun-2022 Funds Transfer - MB # 20010563116,Transferref.232022180646120606 Transferref.232022180646120606 6652.0 248,031.43 23-Jun-2022 Funds Transfer - MB # 20001957673,Transferref.23312214061431100031 Transferref.23312214061431100031 41200.0 254,683.43 22-Jun-2022 Bankak Fees - Funds Transfer - MB #20010530021 ,Transfer ref.225322200629053100005 Transferref.225322200629053100005 10.0 213,483.43 22-Jun-2022 Funds Transfer - MB # 20010530021,Transferref.225322200629053100005 Transferref.225322200629053100005 50000.0 213,493.43 22-Jun-2022 Funds Transfer - MB # 20001728503,Transferref.22232216065923296 Transferref.22232216065923296 248000.0 263,493.43 21-Jun-2022 Bankak Fees - Funds Transfer - MB #20010480587 ,Transfer ref.211622150699216100013 Transferref.211622150699216100013 10.0 15,493.43 21-Jun-2022 Funds Transfer - MB # 20010480587,Transferref.211622150699216100013 Transferref.211622150699216100013 50000.0 15,503.43 21-Jun-2022 Funds Transfer - MB # 20003484214,Transferref.211322150645513576 Transferref.211322150645513576 7000.0 65,503.43
I just want the pattern for each part
i'm using php , any idea ?
CodePudding user response:
We can use preg_match_all
along with an appropriate regex pattern:
$input = "21-Jun-2021 Bank Fees - Funds Transfer - MB #20010598278 ,Transfer ref.250922020633209684 Transferref.250333020633209684 1234.0 143,956.43";
preg_match_all("/(\d{1,2}-\w{3}-\d{4}) .*? MB #(\d ).*? (\d (?:\.\d )?) \d{1,3}(?:,\d{3})*(?:\.\d )?\b/", $input, $matches);
echo $matches[1][0] . "\n";
echo $matches[2][0] . "\n";
echo $matches[3][0];
This prints:
21-Jun-2021
20010598278
1234.0