Lua正则表达式语言元素

  • . --- 代表任何字符
  • %a --- 代表任何字母. 即[a-zA-Z]
  • %c --- 代表任何的控制字符.
  • %d ---代表任何的数字字符. 即[0-9]
  • %l --- 代表所有的小写字母. 即[a-z]
  • %p --- 代表所有的标点符号字符.
  • %s --- 代表所有空格,tab 字符.
  • %u --- 代表所有的大写字母. 即[A-Z]
  • %w --- 代表所有的字母数字. 即[a-zA-Z0-9]
  • %x --- 代表16进制数字.
  • %z --- 代表字符值是 0 的字符. 注意:值为0 的字符是无法正常表达的在表达式中,如果你要使用他,请使用 %z .
  • %x (x是任何非字母和数字的字符) 
  • %% 表示 % , %$ 表示 $
  • [set] --- 代表一个字符集合. 如果要表达一个范围集合,在范围开始的字符和结尾的字符之间使用 - 
  • [^set] --- 表达所有不出现在集合内的.

量词:
  • * -- 0或多次,贪婪匹配.
  • + -- 1或多次,贪婪匹配.
  • - -- 0或多次,非贪婪匹配
  • ? -- 0或1次匹配.

另外一些用法:

  • %n -- n must be a number between 1 and 9. Matches the nth captured substring (see below)
  • %bxy -- matches a substring starting with x and ending with y. The substring must also have the same number of x and y.
  • ^ -- When at the beginning of a pattern, it forces the pattern to match the beginning of a string
  • $ -- When at the end of a pattern, it forces the pattern to match the end of a string
  • When ^ or $ is anywhere else in a pattern, it has no special meaning.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值