regex-negation

Negate characters in Regular Expression

这一生的挚爱 提交于 2019-11-26 22:24:37
问题 How would I write a regular expression that matches the following criteria? No numbers No special characters No spaces in a string 回答1: The caret inside of a character class [^ ] is the negation operator common to most regular expression implementations (Perl, .NET, Ruby, Javascript, etc). So I'd do it like this: [^\W\s\d] ^ - Matches anything NOT in the character class \W - matches non-word characters (a word character would be defined as a-z, A-Z, 0-9, and underscore). \s - matches

Regex to match string not ending with pattern

痞子三分冷 提交于 2019-11-26 21:35:31
问题 I try to find a regex that matches the string only if the string does not end with at least three '0' or more. Intuitively, I tried: .*[^0]{3,}$ But this does not match when there one or two zeroes at the end of the string. 回答1: If you have to do it without lookbehind assertions (i. e. in JavaScript): ^(?:.{0,2}|.*(?!000).{3})$ Otherwise, use hsz's answer. Explanation: ^ # Start of string (?: # Either match... .{0,2} # a string of up to two characters | # or .* # any string (?!000) # (unless

How do I turn any regex into an complement of itself without complex hand editing?

谁都会走 提交于 2019-11-26 20:38:18
问题 The following are pseudo examples, not real regex, but still an example of what I mean: .* (anything) -.* (NOT anything) [A-Z] (Any letter A to Z, caps only) -[A-Z] (NOT any letter A to Z, caps only) EDIT: Changed inverse into complement in the question. Here's where the change was made: "turn any regex into an complement of itself " 回答1: First of all, I believe you mean the complement of a regular expression, not it's inverse. The inverse of a regular expression doesn't make much sense; but

How to replace all BUT the first occurrence of a pattern in string

﹥>﹥吖頭↗ 提交于 2019-11-26 18:21:21
问题 quick question: my pattern is an svg string and it looks like l 5 0 l 0 10 l -5 0 l 0 -10 To do some unittest comparison against a reference I need to ditch all but the first l I know i can ditch them all and put an 'l' upfront, or I can use substrings. But I'm wondering is there a javascript regexp idiom for this? 回答1: You can try a negative lookahead, avoiding the start of the string: /(?!^)l/g See if online: jsfiddle 回答2: There's no JS RegExp to replace everything-but-the-first-pattern

RegExp matching string not starting with my

半世苍凉 提交于 2019-11-26 17:56:55
问题 For PMD I'd like to have a rule which warns me of those ugly variables which start with my. This means I have to accept all variables which do NOT start with my. So, I need a RegEx (re) which behaves as follows: re.match('myVar') == false re.match('manager') == true re.match('thisIsMyVar') == true re.match('myOtherVar') == false re.match('stuff') == true I've tried different ones (will list them here later, sorry, no access to them right now) but haven't got it working yet. 回答1: You could

Regex to get the words after matching string

寵の児 提交于 2019-11-26 17:27:33
问题 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. ^.*

Using regex to match string between two strings while excluding strings

点点圈 提交于 2019-11-26 17:15:51
问题 Following on from a previous question in which I asked: How can I use a regular expression to match text that is between two strings, where those two strings are themselves enclosed two other strings, with any amount of text between the inner and outer enclosing strings? I got this answer: /outer-start.*?inner-start(.*?)inner-end.*?outer-end/ I would now like to know how to exclude certain strings from the text between the outer enclosing strings and the inner enclosing strings. For example,

RegEx to exclude a specific string constant [duplicate]

余生颓废 提交于 2019-11-26 17:14:11
This question already has an answer here: Regular expression to match a line that doesn't contain a word 29 answers Can regular expression be utilized to match any string except a specific string constant let us say "ABC" ? Is this possible to exclude just one specific string constant? Thanks your help in advance. Daniel Brückner You have to use a negative lookahead assertion. (?!^ABC$) You could for example use the following. (?!^ABC$)(^.*$) If this does not work in your editor, try this. It is tested to work in ruby and javascript: ^((?!ABC).)*$ In .NET you can use grouping to your advantage

Regex matching between two strings?

依然范特西╮ 提交于 2019-11-26 14:45:55
I can't seem to find a way to extract all comments like in following example. >>> import re >>> string = ''' ... <!-- one ... --> ... <!-- two -- -- --> ... <!-- three --> ... ''' >>> m = re.findall ( '<!--([^\(-->)]+)-->', string, re.MULTILINE) >>> m [' one \n', ' three '] block with two -- -- is not matched most likely because of bad regex. Can someone please point me in right direction how to extract matches between two strings. Hi I've tested what you guys suggested in comments.... here is working solution with little upgrade. >>> m = re.findall ( '<!--(.*?)-->', string, re.MULTILINE) >>>

Regular expression that doesn&#39;t contain certain string [duplicate]

一曲冷凌霜 提交于 2019-11-26 14:19:32
This question already has an answer here: Regular expression to match a line that doesn't contain a word 29 answers I have something like this aabbabcaabda for selecting minimal group wrapped by a I have this /a([^a]*)a/ which works just fine But i have problem with groups wrapped by aa , where I'd need something like /aa([^aa]*)aa/ which doesn't work, and I can't use the first one like /aa([^a]*)aa/ , because it would end on first occurence of a , which I don't want. Generally, is there any way, how to say not contains string in the same way that I can say not contains character with [^a] ?