Regular expression for APO and FPO The cause of the problem When the city is APOAPKO, because the name of the city is stars with APO

I need to limit the APO FPO address for the city. I did this using this regex

var regExp : RegExp = new RegExp('^[af][ .]?p[ .]?o|[P|p]*(OST|ost)*\.*\s*[O|o|0]*(ffice|FFICE)*\.*\s*[B|b][O|o|0][X|x]','i');

It works only when there is a pattern APO, FPO, A.p.o, F.P.O, etc., but it is still the same with the city APOPKO, which should not happen.

I tried to give \bafter [af][ .]?p[ .]?o, but did not work for me. Can anyone help with this

Thanks in advance.

+4
source share
1 answer

you can use

^([af][ .]?p[ .]?o|[Pp]*(OST|ost)*)\b\.*\s*[Oo0]*(ffice|FFICE)*\.*\s*[Bb][Oo0][Xx]

Watch the regex demo

I cleaned up your template a bit, but the POI ^([af][ .]?p[ .]?o|[Pp]*(OST|ost)*)\b:

  • ^ -
  • ( - : ...
    • [af][ .]?p[ .]?o - apo - : [af] a, f, [ .]? (1 0) , p p, [ .]? o o.
    • | -
    • [Pp]*(OST|ost)*) - p p 0+ (, ? - 1 0 ), OST, OST, 0+ .
  • \b -
+3

All Articles