使用正则表达式排除字符串 [英] Excluding strings using regex
问题描述
我正在创建一个正则表达式,其中包含除时间"、小时"、分钟"之外的所有模式所以,解决了这个问题:
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.
请帮忙.
谢谢
推荐答案
^(?:(?!time|hour|minute).)*$
|
是交替.这意味着在字符串中的所有点,我们都不会查看任何这些表达式(时间、小时或分钟).[]
是错误的,因为它创建了一个字符类.
|
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.
所以这意味着,不看(a t、i、m 或 e),然后(a h、o、u 或 r)等.
So it means, not looking at (a t, i, m, or e), then (a h, o, u, or r), etc.
这篇关于使用正则表达式排除字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!