Problem detecting forward slash in preg_replace regex pattern
I am ru开发者_如何学编程nning 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?
Try
preg_replace('#([A-Za-z0-9/]*)#i', $repl, $subj);
Using alternate delimiters makes it much simpler.
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.
精彩评论