正则表达式中的字符失败



我有一个有效的表达式,除了我希望它看到一个;除了第一个字符以外的任何地方,我希望它失败。 它适用于(根据需要)

; 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 

最新更新