regex-negation

python-re: How do I match an alpha character

丶灬走出姿态 提交于 2019-11-27 08:49:48
How can I match an alpha character with a regular expression. I want a character that is in \w but is not in \d . I want it unicode compatible that's why I cannot use [a-zA-Z] . Your first two sentences contradict each other. "in \w but is not in \d " includes underscore. I'm assuming from your third sentence that you don't want underscore. Using a Venn diagram on the back of an envelope helps. Let's look at what we DON'T want: (1) characters that are not matched by \w (i.e. don't want anything that's not alpha, digits, or underscore) => \W (2) digits => \d (3) underscore => _ So what we don't

Regular Expression to exclude set of Keywords

☆樱花仙子☆ 提交于 2019-11-27 06:29:41
I want an expression that will fail when it encounters words such as "boon.ini" and "http". The goal would be to take this expression and be able to construct for any set of keywords. ^(?:(?!boon\.ini|http).)*$\r?\n? (taken from RegexBuddy 's library) will match any line that does not contain boon.ini and/or http. Is that what you wanted? Tim An alternative expression that could be used: ^(?!.*IgnoreMe).*$ ^ = indicates start of line $ = indicates the end of the line (?! Expression) = indicates zero width look ahead negative match on the expression The ^ at the front is needed, otherwise when

Regex to match anything but two words

柔情痞子 提交于 2019-11-27 04:23:04
问题 I'm trying to write a regular expression to match anything that isn't "foo" and "bar". I found how to match anything but one word at Regular expression to match a line that doesn't contain a word? but I'm not very skilled with regex and am unsure of how to add a second word to this critera. Any help would be most appreciated! CLARIFICATION: I wanted to match on anything that wasn't EXACTLY foo or bar. 回答1: Answer to the question: "A Regular Expression to match anything that isn't "foo" and

IPV6 address into compressed form in Java

那年仲夏 提交于 2019-11-27 03:52:09
问题 I have used Inet6Address.getByName("2001:db8:0:0:0:0:2:1").toString() method to compress IPv6 address, and the output is 2001:db8:0:0:0:0:2:1 ,but i need 2001:db8::2:1 . , Basically the compression output should based on RFC 5952 standard , that is 1) Shorten as Much as Possible : For example, 2001:db8:0:0:0:0:2:1 must be shortened to 2001:db8::2:1.Likewise, 2001:db8::0:1 is not acceptable, because the symbol "::" could have been used to produce a shorter representation 2001:db8::1. 2)

JSLint “insecure ^” in regular expression

倾然丶 夕夏残阳落幕 提交于 2019-11-27 01:56:55
JSLint reports Insecure '^' for the following line. Why is that? Or is it just going to complain any time I want to negate a character class? // remove all non alphanumeric, comma and dash characters "!$7s-gd,&j5d-a#".replace(/[^\w,\-]/g, ''); It only will do this if you have the option selected at the bottom: Disallow insecure . and [^...] in /RegExp/ From the docs : true if . and [^...] should not be allowed in RegExp literals. These forms should not be used when validating in secure applications. So the answer your question, if you start a regex with ^ and it's checked, yes it'll throw the

Regex: match pattern as long as it's not in the beginning

▼魔方 西西 提交于 2019-11-27 01:47:25
问题 Assume the following strings: aaa bbb ccc bbb aaa ccc I want to match aaa as long as it is not at the start of the string. I'm trying to negate it by doing something like this: [^^]aaa But I don't think this is right. Using preg_replace . 回答1: You can use a look behind to make sure it is not at the beginning. (?<!^)aaa 回答2: Since I came here via Google search, and was interested in a solution that is not using a lookbehind , here are my 2 cents. The [^^]aaa pattern matches a character other

Regex to get the words after matching string

拈花ヽ惹草 提交于 2019-11-27 00:35:12
Below is the Content: Subject: Security ID: S-1-5-21-3368353891-1012177287-890106238-22451 Account Name: ChamaraKer Account Domain: JIC Logon ID: 0x1fffb Object: Object Server: Security Object Type: File Object Name: D:\ApacheTomcat\apache-tomcat-6.0.36\logs\localhost.2013-07-01.log Handle ID: 0x11dc I need to capture the words after the Object Name: word in that line. Which is D:\ApacheTomcat\apache-tomcat-6.0.36\logs\localhost.2013-07-01.log . I hope somebody can help me with this. ^.*\bObject Name\b.*$ matches - Object Name The following should work for you: [\n\r].*Object Name:\s*([^\n\r]*

Regex - Does not contain certain Characters

半世苍凉 提交于 2019-11-27 00:00:32
I need a regex to match if anywhere in a sentence there is NOT either < or >. If either < or > are in the string then it must return false. I had a partial success with this but only if my < > are at the beginning or end: (?!<|>).*$ I am using .Net if that makes a difference. Thanks for the help. ^[^<>]+$ The caret in the character class ( [^ ) means match anything but, so this means, beginning of string, then one or more of anything except < and > , then the end of the string. Here you go: ^[^<>]*$ This will test for string that has no < and no > If you want to test for a string that may have

Unix grep regex containing 'x' but not containing 'y'

做~自己de王妃 提交于 2019-11-26 23:01:07
问题 I need a single-pass regex for unix grep that contains, say alpha, but does not contain beta. grep 'alpha' <> | grep -v 'beta' 回答1: ^((?!beta).)*alpha((?!beta).)*$ would do the trick I think. 回答2: The other answers here show some ways you can contort different varieties of regex to do this, although I think it does turn out that the answer is, in general, “don’t do that”. Such regular expressions are much harder to read and probably slower to execute than just combining two regular

Regex: Matching by exclusion, without look-ahead - is it possible?

人走茶凉 提交于 2019-11-26 22:29:18
In some regex flavors, [negative] zero-width assertions (look-ahead/look-behind) are not supported. This makes it extremely difficult (impossible?) to state an exclusion. For example "every line that does not have "foo" on it", like this: ^((?!foo).)*$ Can the same thing be achieved without using look-around at all (complexity and performance concerns set aside for the moment)? UPDATE: It fails "with two ff before oo" as @Ciantic pointed out in the comments. ^(f(o[^o]|[^o])|[^f])*$ NOTE: It is much much easier just to negate a match on the client side instead of using the above regex. The