views:

26

answers:

2

I am running preg_replace across a string which may contain street numbers. The pattern I'm using is:

([A-Za-z0-9]*)/i

This works fine for numbers such as 1, 1a, 123 etc.

However it does not pick up street numbers like 1/54B

I tried to add a forward slash to the pattern like this:

([A-Za-z0-9\/]*)/i

But it isn't picking up numbers like 1/54B.

Any ideas on what I should be using?

A: 

Try

preg_replace('#([A-Za-z0-9/]*)#i', $repl, $subj);

Using alternate delimiters makes it much simpler.

Matthew Flaschen
A: 

I realised that in this example I had overlooked that the forward slash was being translated into URL friendly code (%2F) so

([A-Za-z0-9\%]*)/i

worked for this situation. Yup, I feel stupid.

Thank you to Matthew for his useful tip. Going to file that one away.

Tama