且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

基于THIS或THAT的正则表达式

更新时间:2022-11-14 19:54:47

您可以使用此正则表达式获取所有3个组:

You can use this regex to get all 3 groups:

(?m)^(#.*)|^([^=]+)=(.*)

RegEx演示

正则表达式分解:


  • (?m):启用 MULTILINE 模式

  • ^(#。*):匹配#1组中以开头的整行

  • | :或

  • ^([^ =] +)= :匹配到 = 并捕获到#2组中,然后捕获 =

  • (。*):匹配#3组中的其余行

  • (?m): Enable MULTILINE mode
  • ^(#.*): match a full line starting with # in group #1
  • |: OR
  • ^([^=]+)=: Match till = and capture in group #2 followed by =
  • (.*): Match rest of line in group #3