分隔符的正则表达式
需要有关正则表达式的帮助
如何编写一个表达式来过滤分隔符(制表符、逗号、分号)之间的所有内容?所有前面/后面的空格也必须消失。
示例输入
Abra Cadabra ; Harry Potters,Magic Wand[tab]Sucks!
匹配
[Abra Cadabra]
[Harry Potters]
[Magic Wand]
[Sucks!]
不需要
[Abra Cadabra ]
我想出了这个来选择所有内容,但输出想要
\s*[,;\t\n]\s*
有什么方法可以“反转”它吗?
Need some help with a regular expression
How can I write an expression that filters everything between the delimiters (tab, comma, semicolon)? All the preceeding/trailing spaces must go as well.
Example input
Abra Cadabra ; Harry Potters,Magic Wand[tab]Sucks!
Matches
[Abra Cadabra]
[Harry Potters]
[Magic Wand]
[Sucks!]
Not desired
[Abra Cadabra ]
I came up with this to select everything BUT the output wanted
\s*[,;\t\n]\s*
Is there any way to "reverse" it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
就简单的匹配/搜索而言,这个似乎有效:
顺便说一句,我同意凯文的评论,我会使用类似
string.split(/\s*[,;\t]+\s*/)
As far as simple match/search goes, this one seems working:
BTW, I agree with kevin's comment up there, I'd use something like
string.split(/\s*[,;\t]+\s*/)
你应该能够使用这个。
You should be able to use this.
有一种东西是否定字符类(你必须向下滚动一点) 。试试这个:
它适用于基于 .NET 的 Expresso。
玩那个圆形的东西,我认为
[^,;\t\n]*\b
可能会给你你想要的......There is such a thing as a negated character class (you have to scroll down a bit). Try this:
It works in Expresso, which is .NET-based.
Playing with that rubular thing, I think
[^,;\t\n]*\b
may give you what you want...