使用正则表达式排除字符串
我正在创建一个正则表达式,其中包含除“时间”、“小时”、“分钟”之外的所有模式 所以,解决了这个问题:
^(?:(?!time).)*$
我如何添加其他两个单词?我尝试如下,但这是不正确的。
^(?:(?![time][hour][minute]).)*$
有更好的方法吗?
我没有添加可以接受的值,因为它的范围从数字到字母到符号等。
请帮忙。
谢谢
I was working on creating a regex which will include all patterns except 'time', 'hour', 'minute'
so, worked this out:
^(?:(?!time).)*$
how do i add for the other 2 words also? I tried as follows but it is incorrect.
^(?:(?![time][hour][minute]).)*$
Is there a better way to do this?
I am not adding the values which can be accepted as it ranges from numbers to alphabets to symbols etc.
Please help.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
|
是交替。这意味着在字符串中的所有点,我们都不会查看任何这些表达式(时间、小时或分钟)。[]
是错误的,因为它创建了一个字符类。所以这意味着,不看(at、i、m 或 e),然后看(ah、o、u 或 r)等。
|
is alternation. This means that at all points in the string, we are not looking at any of those expressions (time, hour, or minute).[]
is wrong because that creates a character class.So it means, not looking at (a t, i, m, or e), then (a h, o, u, or r), etc.
我将在这里采取不同的方法:
!/time|hour|month/
有什么问题吗?过度使用正则表达式通常是一个坏主意。I'm going to take a different approach here: what's wrong with
!/time|hour|minute/
? excessive use of regex is usually a bad idea.通过阅读你的问题,我猜你只想要不包含“时间”、“小时”或“分钟”一词的“行”。尝试一些像...
From reading your question, I am guessing you only want "lines" that do not contain the words "time", "hour", or "minute". Try something like...