regex-negation

Regex to match against something that is not a specific substring

余生长醉 提交于 2019-11-30 22:05:36
问题 I am looking for a regex that will match a string that starts with one substring and does not end with a certain substring. Example: // Updated to be correct, thanks @Apocalisp ^foo.*(?<!bar)$ Should match anything that starts with "foo" and doesn't end with "bar". I know about the [^...] syntax, but I can't find anything that will do that for a string instead of single characters. I am specifically trying to do this for Java's regex, but I've run into this before so answers for other regex

Regex negation?

岁酱吖の 提交于 2019-11-30 17:54:30
I'm playing Regex Golf ( http://regex.alf.nu/ ) and I'm doing the Abba hole. I have the following regex that matches the wrong side entirely (which is what I was trying to do): (([\w])([\w])\3\2) However, I'm trying to negate it now so it matches the other side. I can't seem to figure that part out. I tried: (?!([\w])([\w])\3\2) But that didn't work. Any tips from the regex masters? You can make it much shorter (and get more points) by simply using . and removing unnecessary parens: ^(?!.*(.)(.)\2\1) It just makes sure that there's no "abba" ("abba" here means 4 letters in that particular

In Visual Studio 2010, how do you search for text that is not within a single line comment?

半腔热情 提交于 2019-11-30 15:22:23
问题 In Visual Studio 2010, how do you search for text that is not within a single line comment? E. G. how to find "bas" in: foo bar bas but not in foo bar // bas Note that it should find the line: foo / bar / bas (edit) And it should not find the line: foo // bar bas 回答1: Okay, so I asked this question just so I could refer back to my own answer. Visual Studio doesn't seem to have the typical look-ahead, look-behind constructs. It does have a similar zero-width negative assertion. The syntax is ~

RegEx for no whitespace at the beginning and end

别说谁变了你拦得住时间么 提交于 2019-11-30 15:06:05
I want to design an expression for not allowing whitespace at the beginning and at the end of a string, but allowing in the middle of the string. The regex I've tried is this: \^[^\s][a-z\sA-Z\s0-9\s-()][^\s$]\ war1oc This should work: ^[^\s]+(\s+[^\s]+)*$ If you want to include character restrictions: ^[-a-zA-Z0-9-()]+(\s+[-a-zA-Z0-9-()]+)*$ Explanation: the starting ^ and ending $ denotes the string. considering the first regex I gave, [^\s]+ means at least one not whitespace and \s+ means at least one white space . Note also that parentheses () groups together the second and third fragments

In Visual Studio 2010, how do you search for text that is not within a single line comment?

烂漫一生 提交于 2019-11-30 13:40:59
In Visual Studio 2010, how do you search for text that is not within a single line comment? E. G. how to find "bas" in: foo bar bas but not in foo bar // bas Note that it should find the line: foo / bar / bas (edit) And it should not find the line: foo // bar bas Tony Okay, so I asked this question just so I could refer back to my own answer. Visual Studio doesn't seem to have the typical look-ahead, look-behind constructs. It does have a similar zero-width negative assertion. The syntax is ~(x) which means the pattern does not match x at this point in the pattern. Using this construct, I came

Excluding strings using regex

泄露秘密 提交于 2019-11-30 09:51:19
问题 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 回答1: ^(?:(?!time|hour|minute).)*$ | is alternation. This means that at all points in

R-regex: match strings not beginning with a pattern

守給你的承諾、 提交于 2019-11-30 04:56:43
I'd like to use regex to see if a string does not begin with a certain pattern. While I can use: [^ to blacklist certain characters, I can't figure out how to blacklist a pattern. > grepl("^[^abc].+$", "foo") [1] TRUE > grepl("^[^abc].+$", "afoo") [1] FALSE I'd like to do something like grepl("^[^(abc)].+$", "afoo") and get TRUE , i.e. to match if the string does not start with abc sequence. Note that I'm aware of this post , and I also tried using perl = TRUE , but with no success: > grepl("^((?!hede).)*$", "hede", perl = TRUE) [1] FALSE > grepl("^((?!hede).)*$", "foohede", perl = TRUE) [1]

replace characters in notepad++ BUT exclude characters inside single quotation marks(2nd)

[亡魂溺海] 提交于 2019-11-29 16:50:51
replace characters in notepad++ BUT exclude characters inside single quotation marks Sorry to all users (especially to Avinash Raj) who answered already 1st similiar question - I did simply forget the 2nd kind of string. (And (that is the sad thing) - I'm not able to adjust the solution from 1st similiar question to the 2nd kind of string...) I have TWO different strings in this kind: SELECT column_name FROM table_name WHERE column_name IN ('A' , 'st9u' ,'Meyer', ....); WHERE a.object_type IN (' 'TABLE'', ''MATEerialIZED VIE3W' ') I want replace all characters in notepad++ from upper to lower,

Excluding strings using regex

一曲冷凌霜 提交于 2019-11-29 16:44:22
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 ^(?:(?!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

regular expression - match word only once in line

爷,独闯天下 提交于 2019-11-29 13:47:33
Case: ehello goodbye hellot hello goodbye ehello goodbye hello hello goodbye I want to match line 1 (only has 'hello' once!) DO NOT want to match line 2 (contains 'hello' more than once) Tried using negative look ahead look behind and what not... without any real success.. A simple option is this (using the multiline flag and not dot-all): ^(?!.*\bhello\b.*\bhello\b).*\bhello\b.*$ First, check you don't have 'hello' twice, and then check you have it at least once. There are other ways to check for the same thing, but I think this one is pretty simple. Of course, you can simple match for