Special characters in regular expression

There are some special characters in Regular Expressions.Within a pattern,all characters except .,|,(,),[,],{,},+,\,^,$,*,and ? match themselves.They are the special characters.If you know their meaning in the Regular Expressions you can know why are they special.If you want to use themselves in patterns,you need add '\' before them.The following are the meaning of them:
  • '.':represents any character except a newline
  • '|':Its meaning is 'or'
  • '(' and ')':
  • '[' and ']':A character class is a set of characters between brackets:[characters] matches any single character between the brackets.
  • '{' and '}':
  • '+':follow a character or a () expression to express the character or expression must contains more than one times.
  • '\':
  • '^':a anchor.match the begining of a line
  • '$':a anchor.match the end of a line or ...
  • '*':
  • '?':
Copy the list of these from <the ruby way>:
  • ^ Beginning of a line or string

  • $ End of a line or string

  • . Any character except newline (unless POSIX)

  • \w Word character (digit, letter, or underscore)

  • \W Non-word character

  • \s Whitespace character (space, tab, newline, and so on)

  • \S Non-whitespace character

  • \d Digit (same as [0-9])

  • \D Non-digit

  • \A Beginning of a string

  • \Z End of a string or before newline at the end

  • \z End of a string

  • \b Word boundary (outside [ ] only)

  • \B Non-word boundary

  • \b Backspace (inside [ ] only)

  • [ ] Any single character of set

  • * Zero or more of the previous subexpression

  • *? Zero or more of the previous subexpression (non-greedy)

  • + One or more of the previous subexpression

  • +? One or more of the previous subexpression (non-greedy)

  • {m,n} M to n instances of the previous subexpression

  • {m,n}? M to n instances of the previous subexpression (non-greedy)

  • ? Zero or one instance of the previous regular expression

  • | Alternatives

  • ( ) Grouping of subexpressions

  • (?# )

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值