tags:

views:

180

answers:

4

Hi alll

I have strings like follow

field_zip_code:"48103"

taxonomy:88 field_zip_code:"48103"

taxonomy:88 field_state:"MI" field_zip_code:"48103"

From here i want to extract variable values like 48103,88,MI

i need regular expressions in PHP,

Thanks in advance Kamal

A: 

You better use three regular expressions for the three fields you want

field_zip_code:"(\d+)"
taxonomy:(\d+)
field_state:"(\w+)"
Otto Allmendinger
a bit primitive eh?
Rook
if by primitive you mean readable, then yes
Otto Allmendinger
A: 

There is no proper grammar to apply the regex to :(

Sarfraz
A: 

If the 3 fields are always ordered like this,

^(?:taxonomy:(\d+))?\s*(?:field_state:"([^"]+)")?\s*(?:field_zip_code:"([^"]+)")$

Otherwise, perform 3 matches as @Otto suggested.

KennyTM
A: 

I encourage you to also be thinking about non-standard zipcodes. 009HH, for example, is a valid ZIP in the US Postal Mail system.

Also, do think about Canadian zipcodes if your business needs to support them - they're in a radically different format.

Alex