浅尝'则'止: 正则

Screenshot from LEARN REGEX.

Image

  • [a-z0-9] 与 (a-z0-9)的区别, []是chracter class, 只匹配一个字符, ()代表匹配组, 这个例子只能匹配’a-z0-9’

Image

  • 前向/后向断言

Image

  • 例子
“(T t)he(?=sfat)” => The fat cat sat on the mat.  
“(T t)he(?!sfat)” => The fat cat sat on the mat.  
”(?<=(T t)hes)(fat mat)” => The fat cat sat on the mat.
”(?<!(T t)hes)(cat)” => The cat sat on cat.  
  • Flag

Image

  • 搭建引擎

相关资源:

正则表达式可视化: regexer

正则表达式: Regulex

正则在线调试: regex101

正则在线答题: regexone

正则引擎原理: Regular Expression Matching Can Be Simple And Fast




    Enjoy Reading This Article?

    Here are some more articles you might like to read next:

  • What is Mathematics: Solution Chapter 3
  • What is Mathematics: Solution Chapter 2
  • What is Mathematics: Solution Chapter 1
  • A small guide to supplements: What you need to know
  • 混乱与秩序