regex-negation

RegEx in JS to find No 3 Identical consecutive characters

落爺英雄遲暮 提交于 2019-12-11 01:48:12
问题 How to find a sequence of 3 characters, 'abb' is valid while 'abbb' is not valid, in JS using Regex (could be alphabets,numerics and non alpha numerics). This question is a variation of the question that I have asked in here : How to combine these regex for javascript. This is wrong : /(^([0-9a-zA-Z]|[^0-9a-zA-Z]))\1\1/ , so what is the right way to do it? 回答1: This depends on what you actually mean. If you only want to match three non-identical characters (that is, if abb is valid for you),

Regular expression with optional part and negative lookahead

风流意气都作罢 提交于 2019-12-10 23:41:37
问题 I need check if a string contains the pattern: starts with "A" followed by zero or more spaces and then anything but not "B". So, the following must match: "A" . "AX" , "A X" , "A " , "A XB" The following strings must not match: "AB" , "A B" My naive attempt was A\s*(?!B) , but it matches the undesirable "A B" . 回答1: If you just need to get true or false, you may put the \s* into the lookahead: Regex.IsMatch(s, @"A(?!\s*B)") It finds A that has no 0+ whitespaces followed with B after it. See

Javascript regex negative look-behind

六月ゝ 毕业季﹏ 提交于 2019-12-10 22:38:42
问题 I'm trying to figure out the correct regex to do this in javascript. In pcre, this does exactly what I want: /^.*(?<!\/)kb([0-9]+).*$/im Goal: If I have a value that isn't prefixed with a forward-slash, e.g KB 12345 , it'll match the number within. If that value is prefixed with a forward-slash it won't match, e.g: http://someurl.com/info/KB12345 However it looks like while this works in pcre, it won't work in javascript due to the syntax of the negation: (?<!\/) I've been trying to figure

How to fix a BBcode regular expression

落爺英雄遲暮 提交于 2019-12-10 20:57:42
问题 I have a regular expression that grabs BBcode tags. It works great except for a minor glitch. Here is the current expression: \[([^=\[\]]+)[=\x22']*([^ \[\]]*)['\x22]*\](.+)\[/\1\] Here is some text it successfully matches against and the groups it builds: [url=http://www.google.com]Go to google![/url] 1: url 2: http://www.google.com 3: Go to google! [img]http://www.somesite.com/someimage.jpg[/img] 1: img 2: NULL 3: http://www.somesite.com/someimage.jpg [quote][quote]first nested quote[/quote

Regex match everything but

[亡魂溺海] 提交于 2019-12-10 10:49:16
问题 I would like to create a regular expression to match every word, whitespace, punctuation and special characters in a string except for specific keywords or phrases. Because I only can modify regex, not server code I have to use match instead of replace. I have something like this so far: (?!(quick|brown|fox|the lazy))\b\w+ but it ignores white spaces and special characters in this tool Thanks. 回答1: Does this work for you (?!(quick|brown|fox|the lazy))(\b\w+|[^\w]) ? Do you have any examples?

Regex with exclusion chars and another regex

泪湿孤枕 提交于 2019-12-10 10:28:35
问题 How to write regex which find word (without whitespace) that doesn't contain some chars (like * or # ) and sentence also (like level10 or level2 - it should be also regex - level[0-9]+ ). It will be simple for chars excluded ( [^\\s^#^*]+ ) but how to exclude this 'level' example too ? I want to exclude chars AND level with number. Examples: weesdlevel3fv - shouldn't match because of 'level3' we3rlevelw4erw - should match - there is level without number dfs3leveldfvws#3vd - shouldn't match -

Extending regular expression syntax to say 'does not contain text XYZ'

半世苍凉 提交于 2019-12-10 01:24:07
问题 I have an app where users can specify regular expressions in a number of places. These are used while running the app to check if text (e.g. URLs and HTML) matches the regexes. Often the users want to be able to say where the text matches ABC and does not match XYZ . To make it easy for them to do this I am thinking of extending regular expression syntax within my app with a way to say ' and does not contain pattern '. Any suggestions on a good way to do this? My app is written in C# .NET 3.5

Regex negation?

三世轮回 提交于 2019-12-09 00:25:37
问题 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? 回答1: You can make it much shorter (and get more points) by simply using . and removing unnecessary parens: ^(?!.*

How to find a word NOT preceded by another specific word?

亡梦爱人 提交于 2019-12-08 20:06:40
问题 Which regular expression can I use to find all strings bar are not preceded by string foo ? Having whitespace between the two is also illegal. So the regex should match the following strings foo is bar hello bar But not these foobar foo bar I've tried using the following (?!<foo)bar and it gets the work done for eliminating foobar , but I need to take care of the whitespace, and of course (?!<foo)\s*bar matches all the strings. Thanks! 回答1: Better to use other facilities of the programming

Regex for matching string not ending or containing file extensions

守給你的承諾、 提交于 2019-12-08 09:45:38
问题 In a Java application, I need to write a String containing a regex for URIs, so that the URI does not contains character sequences like .js? , .css? and .jpg? , but are also not ending with .js , .css and .jpg I made the following: (?:.js|.css|.jpg)$|(?:.js[?]|.html[?]|.jpg[?]) Which basically matches all the URIs ending with the given file extensions or containing the file extension plus the question mark. How can I do the negation of the and of the previous conditions? So, for instance I