doumiang2297 2011-10-29 21:53
浏览 46
已采纳

php 5.1.6的正则表达式

Can someone help me with a regular expression to include

A-z a-z 0-9 - _ (space) (dot) < > ( ) ~

and exclude other special symbols in ereg function of php 5.1.6?

I am getting too much confused with the escape character backslash and order of things i need to write if it is required. If not possible with ereg u can suggest me any similar function that works.

Thank you

  • 写回答

2条回答 默认 最新

  • dopuz8728 2011-10-29 21:59
    关注

    Ereg version :

    if (ereg('^[a-zA-Z0-9.<>()~ _-]+$', $subject)) {
        # Successful match
    }
    

    Preg version : (after popular demand)

    if (preg_match('/^[a-zA-Z0-9.<>()~ _-]+$/', $subject)) {
        # Successful match
    }
    

    Something like this?

    # ^[a-zA-Z0-9.<>()~ _-]+$
    # 
    # Assert position at the beginning of the string «^»
    # Match a single character present in the list below «[a-zA-Z0-9.<>()~ _-]+»
    #    Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
    #    A character in the range between “a” and “z” «a-z»
    #    A character in the range between “A” and “Z” «A-Z»
    #    A character in the range between “0” and “9” «0-9»
    #    One of the characters “.<>()~ ” «.<>()~ »
    #    The character “_” «_»
    #    The character “-” «-»
    # Assert position at the end of the string (or before the line break at the end of the string, if any) «$»
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?