C#交替构造正则表达式

交替构造修改正则表达式以启用/或匹配。 下表列出了交替结构:

  • | - 匹配由垂直竖线(|)字符分隔的任何一个元素。模式:th(e|is|at),如:"the", "this" 匹配 "this is the day. "
  • (?( expression )yes | no ) - 如果表达式匹配yes; 否则匹配可选的no部分。模式:(?(A)A\d{2}\b|\b\d{3}\b),如:"A10", "910" 匹配 "A10 C103 910"
  • (?( name )yes | no ) - 如果命名的捕获名称具有匹配yes; 否则匹配可选的no部分。如:(?< quoted>")?(?(quoted).+?"|\S+\s),如:Dogs.jpg, "Yiska playing.jpg" 匹配 "Dogs.jpg "Yiska playing.jpg""

上一篇: C#正则表达式 下一篇: C#异常处理