FAQ Database Discussion Community


syntax for rejecting items in array with regex

ruby,regex,regex-negation
I have this working for my array: my_arr.delete_if{|x| x=~/achievement\..*?/} it deletes all strings in the array that match the pattern achievement.. Is there a similar one-liner to do the reverse (only accept strings that contain achievement.?...

How to write a java regex to match anything OTHER than a 3 digit number? [closed]

java,regex,regex-negation
It should consider the whole string for comparison. When the whole string is not a three digit number, it should match.

Boost Regex Exclude one character

c++,regex,boost,regex-negation
I'm locking for a boost regular expression that would exclude all strings that contains the character |. "1234|" should be exclude "|eee" should be exclude "...ff" should not be exclude. I can't change the code above to remove the negation of the result of boost::regex_match. if ( !boost::regex_match( sValue, boost::regex("[^\|]")...

Regex that fail when there excessive whitespaces between words

java,regex,regex-negation
I'm trying to make a regex in Java that does not match excessive whitespaces between words, and whitespaces at the beginning and end. I have done this regex so far ^[\\S].*[\\S]$ That fail when there are whitespaces at the beginning and end of a line But how about excessive whitespaces...

Sublime on Save Build exclude pattern

regex,sublimetext,regex-negation,sublime-text-plugin
I installed a Sublime plugin called "SublimeOnSaveBuild" which compiles my sass files while saving. But now I'm going to work with more than just one file. The plugin offers a filter function which is checking if the filename matches the pattern \\.(sass|less|scss)$. But i need a pattern which matches any...

Regular Expression: Match lines not starting with 32 spaces in Notedpad++

regex,notepad++,regex-negation
In Notepad++, I'm trying to match lines not starting with 32 consecutive spaces. I already have the regex that matches lines starting with 32 consecutive spaces: ^ {32}.*$ I tried with ^[^ {32}].*$ and ^[^( {32})].*$ with the same wrong result, doesn't match lines with only 24 spaces for example....

Negative Lookahead/behind Search and Replace Sentences in Sublime Text 3 [duplicate]

regex,sublimetext,sublimetext3,regex-negation,negative-lookbehind
This question already has an answer here: Regular expression to match text that doesn't contain a word? 17 answers I'm editing the text below in Sublime Text 3, I want to remove the sentences that do not contain the string /do not/. Lorem ipsum dolor sit amet, consectetur adipiscing...

Remove non-alphabetic words from a sentence using regex

regex,regex-negation,regex-lookarounds
Is it possible to remove words in a sentence that doesn't contain a-z letters? I've thought about negative look arounds but wasn't successful. For example, This is a 1-2-a3 sample 12 -- 7-8 sentence becomes This is a 1-2-a3 sample sentence Assume all other punctuations were removed except dashes. Thanks!...

Replace part of word with regexp

c#,asp.net,regex,regex-negation
I need to replace replaceString inside words, if it not starting with "@". For example: replaceString - replaced to : replacedString abc.replaceString - replaced to : abc.replacedString [email protected] - NOT replaced Im trying to use something like @"([email protected])replaceString$", but it not working properly....

Incorporate regex quantifier into brackets

javascript,regex,regex-negation
I am trying to incorporate the following negative lookahead regex ^(?!\*\*) into the following regex ^([a-z]:)?(\\[^<>:"/\\|?;,$=%@~]+)+\\?$ Basically, I don't want two consecutive asterisks (**) to appear anywhere in the file path. How do I modify the block [^<>:"/\\|?;,$=%@~] to incorporate this condition? I tried using escape characters, but to no...

Replace all colon character that does not occur after specific word pattern

ruby,regex,replace,regex-negation,replaceall
For a given text like pack: my box with five: dozen: liquor: jugs ::: : I want to replace all the : with ; that occur only after the words ack and zen. So the output I expect here is pack: my box with five; dozen: liquor; jugs ;;; ;...

Match parts of string that are not consecutive stretches of certain character

python,regex,regex-negation
I have a simple function that yields all stretches of at least gapSize consecutive N's from a string: def get_gap_coordinates(sequence, gapSize=25): gapPattern = "N{"+str(gapSize)+",}" p = re.compile(gapPattern) m = p.finditer(sequence) for gap in m: start,stop = gap.span() yield(start,stop) Now I'd like to have a function that does the exact opposite:...

Removing character from regexp class in R

regex,r,regex-negation
Edit: Changing the whole question to make it clearer. Can I remove a single character from one of the regular expression classes in R (such as [:alnum:])? For example, match all punctuation ([:punct:]) except the _ character. I am trying the replace underscores used in markdown for italicizing but the...

postgres regexp_replace negate presence of consecutive groups of chars

postgresql,regex-negation,regexp-replace
i have a database export that come with some wrong chararacter substitution(like è => e'). So i have to change it back in postgres. I'm going crazy to make an all in one regex that catch something like this: cassine' de' pecche' e' it must become cassinè de' pecchè è...

Regex for at least one alphabet and shouldn't allow dot(.)

regex,regex-negation,regular-language
I have written the regex below but I'm facing an issue: ^[^\.]*[a-zA-Z]+$ As per the above regex, df45543 is invalid, but I want to allow such a string. Only one alphabet character is mandatory and a dot is not allowed. All other characters are allowed....

strange regex experasion [on hold]

regex,regex-negation
I've got a quick harmless question... what does this expression mean: /(^|[\s\0])/g

How can I match this string '-,-,-,9,-'?

regex,preg-match,regex-negation
I was told to validate the string like this -,-,-,9,- It was separated by , and contains 1 number(0-9), others are all - some examples: 9,-,-,-,- -,-,-,-,9 -,-,2,-,- How can I match this? And what concepts should I learn in regex? Update I miss the times, sorry, this string can...

RegEx matching space not starting/ending with char

javascript,regex,node.js,regex-negation
I need to split the text to the words but I also need to ignore the & character. That means for example the word "h & m" has stay together. Regex must also work in JavaScript and node.js. I used /(?!&)\s(?!&)/g. But that ignore space with & character only at...

How can I create a regex to match the inner-most match or work from right-to-left?

regex,regex-negation,regex-lookarounds,regex-greedy,grunt-usemin
I'm trying to match the strings for image references but am picking up a little too much when there's an expression involved. In this example http://www.regexr.com/3b3ub, you'll see I'm doing good on the 1st and 3rd matches but I'm getting too much in the 2nd match. I only want the...

Check if string does not contain URL segment and match it

javascript,regex,regex-negation
How to check if URL string does not contain the following string: test/test/posts/search/1234567, so that when I provide the following URL: test/test/1234567 the match function would return: ["test/test/1234567", "test/test/", "", "1234567"]? Update: If I provide /posts/search in URL I would like to omit this regex in re.test(url) function. // var...

Regex to highlight invalid tokens

regex,regex-negation
Hi have a field were the user can enter a string with a limited set of tokens, say {token1}, {token2}. Token is a string between curly braces, no spaces allowed. I want to have the entry of the user checked with regex to invalidate when the user enters any unknown/invalid...

Negate Word Groups? - Regular Expression (Regex)

regex,regex-negation
Its easy to get a regular expression that gets you ALL the "com/net/org" Here it is: ^.+(com|org|net)$ BUT, I'm trying to find all domains that DON'T have a com/net/org I can't seem to find a way to negate the word group com/net/org Here are sample strings: piquetraveldesign.com rigall.com.au hunt4me.co.uk cialis-without-prescription.us...

Regex: how to select of the location with PHP [duplicate]

php,regex,regex-negation,regex-lookarounds
This question already has an answer here: RegEx match open tags except XHTML self-contained tags 36 answers Html code: <div username="bob"> <table> <tr> <td>name</td> <td>alex</td> </tr> <tr> <td>location</td> <td>London</td> </tr> <tr> <td>id</td> <td>123</td> </tr> </table> </div> <div username="apple"> <table> <tr> <td>name</td> <td>david</td> </tr>...

Struggling with negative lookahead in a regex

regex,regex-negation,regex-lookarounds
I humbly request for some guidance on using multiple negative lookaheads in a regex. I currently have a string that matches up against 2 regular expressions. String: Armadale Joe Bloggs 22-333-222 20001 Whitfords to Butler ^Armadale\D+\d{2}-\d{3}-\d{2}\D+2\d{4}\D+$ (Armadale|Fremantle|Butler|Mandurah|Midland|Thornlie)\D+(?![0-9]{2}-[0-9]{3}-[0-9]{2})2[0-9]{4}\D+$ How can I modify Regex 2 so that it doesn't match the string?...

Problems to negate regex pattern

javascript,regex,regex-negation
I have several regex patterns and i have to negate them all, so i am trying to build somo generic regex negate, something like /^(anypattern)/ but I am having troubles.. for example, I have this text: [email protected][email protected]@AAA.AAAooooooooo and this pattern: [A-Z][email protected][A-Z]+\\.[A-Z]{2,4}, I need something to negate this. I would get...

Search for (LaTeX) regex found NOT within another regex (math mode)

regex,regex-negation,regex-lookarounds
I'm trying to find all improperly-written commands in LaTeX that are NOT within math mode. That is, in the following, I want to match "\bad" but NOT "\good\" or "\math". Example of \bad command. Example of \good\ command. And $x=\math + y$ is also a good command. I figured out...

How to match methods without a specific category

c#,regex,regex-negation,qregexp
I need to remove some tests from several classes without some specific category how do I match than? in this example i want to remove only the methods 'Bar' and 'BarTwo' namespace MyNameSpace { /// <summary> /// Some Stuff /// </summary> public class MyClass { [CategoryA] public void Foo() {...

Regular expression - how to negate ^[A-Z]{4}[0-9]{2}$ [duplicate]

regex,regex-negation
This question already has an answer here: Regex negation? 3 answers Regular expression - how to negate ^[A-Z]{4}[0-9]{2}$...

Regex : Remove all commas between a quote separated string [python]

python,regex,regex-negation
What would be an appropriate regex to remove all commas in a string as such: 12, 1425073747, "test", "1, 2, 3, ... " Result: 12, 1425073747, "test", "1 2 3 ... " What I have that matches correctly: "((\d+), )+\d+" However, I obviously cant replace this with $1 $2. I...

Regular expression to include numeric only or character only or ignore first two conditions if alpha numeric

javascript,regex,regex-negation,regex-lookarounds
I wrote Regular expression for the below cases : only numbers(length:4) only alphabets(should contain vowel) ([0-9]{1,4})|((?=[a-z]*[aeiou])[a-z]*) eg: 9987, tyde How to add the below condition? Ignore the first two cases if the string contains alphanumeric characters. eg: 9ty87 ...

Grep exclude line only if multiple patterns match

regex,shell,grep,regex-negation
I want to find lines that do not contain both "path": "/" and "User-Agent": "curl. Lines that contain only one of those should be included. In other words, how can I exclude a line only if it matches multiple patterns?...

Regex for URL to sites

regex,sitemap,regex-negation,regex-greedy,regedit
I have two URLs with the patterns: 1.http://localhost:9001/f/ 2.http://localhost:9001/flight/ I have a site filter which redirects to the respective sites if the regex matches. I tried the following regex patterns for the 2 URLs above: http?://localhost[^/]/f[^flight]/.* http?://localhost[^/]/flight/.* Both URLS are getting redirected to the first site, as both URLs are...

Regex: match “group3.*group1” if group2 is not between groups 3 and 1

regex,python-3.x,regex-negation,regex-lookarounds
I'm using Python 3.4. I have three groups: g1 = 'g11|g12' g2 = 'g21|g22' g3 = 'g31|g32' I want to match any instance of g3, followed by anything except g2, followed by g1. Here are some strings on which I want to find a match: 'g31 anything or nothing g11'...

How to match (group2.*|^.*)group1 when no instance of groups 1,2,3, or 4 are in between?

regex,regex-negation,regex-lookarounds
I'm using Python 3.4. Suppose we have four groups composed of regular expressions g1 = 'g11|g22|...|g1m' g2 = 'g21|g22|...|g2n' g3 = 'g32|g32|...|g3p' g4 = 'g41|g42|...|g4q' For example, g1 might be 'chickens|horses|bonnet(?>!blue )'. The groups are disjoint: no element in any of the four groups belongs to more than one group....

Regex to exclude a specific string but not strings having the substring

regex,regex-negation,regex-lookarounds
I am currently in need of a regex that can exclude a specific string but not words that include that string. For example if you have a string made of 0's and 1's. Any string that contains any number of 1's and any number of 0's except 3 0's exclusively....

Regex and jquery validate. Negate expression

jquery,regex,jquery-validate,regex-negation,negate
I'm working on a addition method for the jquery validate plugin which must detect if 3 or more consecutive identical characters are entered, and prompt a message. To do so I need to negate a regex expression. This is my method: $.validator.addMethod("pwcheckconsecchars", function (value) { return /(.)\1\1/.test(value) // does not...

Reqular expression is not working for inverse maching

java,regex,regex-negation
I have tried the following If the input text contains "test" keyword then the output will be "NOT Match". String line = "placed test here"; String pattern = "^((?!test).)*"; Matcher m = r.matcher(line); if (m.find( )) { System.out.println("MATCH"); } else { System.out.println("NO MATCH"); } ...

Regex to match everything in a string except “
”, “
”, “

regex,regex-negation
I want a regex to match everything in a string except "<br>", "<br />", "<br />". Reason being, i want to put string in a container and want "" tags to execute and display other tags as they are written by the user. For example: String--> "I have <br> <br...

Regex number followed by date with no space

php,regex,regex-negation
I have the following rows: fact prof 45883 factura PROF 46186 FACT.PROF:45126 FACT.PROF.NR.46069 FACTURA PROF. 46296 factura prof.46673 FAC PROFORMA PROF 46876 FACT 44046 FACT 46529 fact proforma nr 46229 FCT PROF:40365 PROF 44283 fact prof 46646 FACT PROF: 45666 fact PROF:45560 Factura proforma : 46059 FCT PROF 45108 fact....