ここに練習用の弦があります。
$message = "Hurray! You've received a $100 Amazon Gift Card. Hope you enjoy this Amazon Gift Card! What's next? Apply the gift card to your Amazon account:=20 https://www.amazon.com/g/ Don't have an Amazon account? Sign up to redeem: www.amazon.com You can also redeem your gift card at checkout using this claim code: NE7N-TUD6NV-GUAB We hope to see you again soon, Amazon.com Once applied to your Amazon account, the entire amount will be added to you= r gift card balance. Your gift card balance can't be transferred to other a= ccounts, used to buy other gift cards, or, except as required by law, redee= med for cash. Your gift card balance will be applied automatically to eligible orders dur= ing the checkout process and when using 1-Click. If you don=E2=80=99t want = to use your gift card balance on your order, you can unselect it as a payme= nt method in checkout.=20 If you experience any issues using your gift card, you can reference your g= ift card by providing the following information to Customer Service: Order Number: 234343433433";
preg_matchを使用してクレームコードを取得したいのですが、失敗します。これは私のコードです。
if(preg_match_all("/claim code:.*\s/", $message, $array)){
print_r($array);
}
出力はこれでした
Array ( [0] => Array ( [0] => claim code: ) )
しかし、クレームコードを表示したいのですが、誰か助けてもらえますか?
私はパターンを使用します(?<=\bclaim code: )\S+
:
$message = "Hurray! You've received a $100 Amazon Gift Card. Hope you enjoy this Amazon Gift Card! What's next? Apply the gift card to your Amazon account:=20 https://www.amazon.com/g/ Don't have an Amazon account? Sign up to redeem: www.amazon.com You can also redeem your gift card at checkout using this claim code: NE7N-TUD6NV-GUAB We hope to see you again soon, Amazon.com Once applied to your Amazon account, the entire amount will be added to you= r gift card balance. Your gift card balance can't be transferred to other a= ccounts, used to buy other gift cards, or, except as required by law, redee= med for cash. Your gift card balance will be applied automatically to eligible orders dur= ing the checkout process and when using 1-Click. If you don=E2=80=99t want = to use your gift card balance on your order, you can unselect it as a payme= nt method in checkout.=20 If you experience any issues using your gift card, you can reference your g= ift card by providing the following information to Customer Service: Order Number: 234343433433";
preg_match_all("/(?<=\bclaim code: )\S+/", $message, $matches);
print_r($matches[0][0]);
これは印刷します:
NE7N-TUD6NV-GUAB
現在のアプローチの主な問題は、正規表現パターン自体です。\s*
0個以上の空白文字に一致する場合は、\S*
上記で使用したように代わりに使用する必要があります。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加