1

最終的解決

/(\d{1,5}\s[^\d].{5,20}(dr|drive)(\.|\s|\,))/i

元の質問

正規表現

/([0-9]{1,5}.{5,20}(dr|drive)(\.|\s|\,))/i

パターン

PO Box 66 23 Britton Drive Bloomfield CT 06002

この正規表現は「66 23 Britton Drive」を返しています。「23 ブリットン ドライブ」を返してほしい。次の正規表現のバリエーションを試しました。

/(([0-9]{1,5}.{5,20})?(dr|drive)(\.|\s|\,))/i - adding a new capturing group and making it uncreedy
/([0-9]{1,5}.{5,20}?(dr|drive)(\.|\s|\,))/i - making the length of in between characters ungreedy
/([0-9]{1,5}.{5,20}(dr|drive)(\.|\s|\,))/Ui - adding ungreedy modifier

うまくいかないパターンの増加

PO Box 156 430 S Wheeling Dr. Wheeling, IL 60090

うまくいくパターン

1195 Columbia Dr PO Box 1256 Longview, WA 98632
3400 SW Washington drive PO Box 1349 Peoria, IL 61654
4

1 に答える 1