0

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?

2 Answers 2

4

Try

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

Using alternate delimiters makes it much simpler.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.