我有一个有效的表达式,但我希望它在看到 ; 时失败。除第一个字符以外的任何位置。它适用于(根据需要)
; Person1: Role1,
但它也适用于(不需要)
; Person1: Role1; Person2: Role2,
因此,尝试找出如何修改以下表达式,使其在第一个字符后的分号上失败(实际上分号只能在第三组中找到):
(^|; )(.+?:)(.+?)(,)
抱歉,我不知道味道。用法是在音乐标记程序的插件中。
最佳答案
如果您不想允许使用分号,请告诉正则表达式引擎:
^;?\s*([^;:]+):\s*([^,;]+),$
说明:
^ # Start of string
;?\s* # Match optional ; and optional whitespace
([^;:]+) # Capture one or more characters except ; and : in group 1
:\s* # Match : and optional whitespace
([^,;]+) # Capture one or more characters except , and ; in group 2
, # Match ,
$ # End of string
关于regex - RegEx 表达式中的字符失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22131453/