什么正则表达式将匹配除逗号‘,‘或分号‘;‘之外的每个字符?

本文翻译自:What regex will match every character except comma ',' or semi-colon ';'?

Is it possible to define a regex which will match every character except a certain defined character or set of characters? 是否可以定义一个正则表达式,该正则表达式将匹配除某个定义的字符或字符集之外的每个字符?

Basically, I wanted to split a string by either comma (,) or semi-colon (;). 基本上,我想用逗号(,)或分号(;)分割字符串。 So I was thinking of doing it with a regex which would match everything until it encountered a comma or a semi-colon. 所以我想用一个正则表达式来完成它,它会匹配所有内容,直到遇到逗号或分号。


#1楼

参考:https://stackoom.com/question/5uaQ/什么正则表达式将匹配除逗号-或分号-之外的每个字符


#2楼

[^,;]+         

You haven't specified the regex implementation you are using. 您尚未指定正在使用的正则表达式实现。 Most of them have a Split method that takes delimiters and split by them. 他们中的大多数都有一个Split方法,它接受分隔符并由它们分割。 You might want to use that one with a "normal" (without ^ ) character class: 您可能希望使用具有“普通”(不带^ )字符类的那个:

[,;]+

#3楼

Use character classes. 使用字符类。 A character class beginning with caret will match anything not in the class. 以插入符号开头的字符类将匹配类中没有的任何内容。

[^,;]

#4楼

用这个:

([^,;]*[,;])*

#5楼

使用负字符类

[^,;]+
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值