Search code examples
phpregexpreg-match

Regular expression match for specific string


I have a below string to compare in PHP.and i made one regular expression for match the string.But it only match exactly same string so can some one help to get me regular expression to match below conditional string.

I have used below expression.

[poBox]\s\d{3}

below is my conditional string to match

POBox 123, POBox 1234, P.O.Box 123, P.O.Box 1234, P O Box 123, P O Box 1234, P.O. Box 123, P.O. Box 1234

Solution

  • [poBox] means any one character between p, o, B or x. And \d{3} will not match the full extent of 1234.

    P\.?\s?O\.?\s?Box\s\d+
    

    regex101.