douzhangkui2467 2010-07-19 22:28
浏览 197
已采纳

在preg_replace正则表达式模式中检测正斜杠的问题

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条回答 默认 最新

  • duanchi8112 2010-07-19 22:36
    关注

    Try

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

    Using alternate delimiters makes it much simpler.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?