regex-negation

RegEx to tell if a string does not contain a specific character

匆匆过客 提交于 2019-12-03 02:04:05
Easy question this time. I'm trying to test whether or not a string does not contain a character using regular expressions. I thought the expression was of the form "[^ x ]" where x is the character that you don't want to appear, but that doesn't seem to be working. For example, Regex.IsMatch("103","[^0]") and Regex.IsMatch("103&","[^&]") both return true (I would expect false). I started using "[^&]" and thought maybe the & needed to be escaped as \&, but it didn't seem to make a difference. Ideas? I assume it's something small. Also, I'm using .NET, so keep that in mind. Edit1: I found this

Capture , if between substring “”

扶醉桌前 提交于 2019-12-03 00:04:49
问题 (?!([^"]*"[^"]*")*[^"]*$), This captures , if it is between "".Lets say the test string is 1 2 3 4 , 5 6 7, 8 9 "10 11 12 , 13 14 15," 16,17,"18,19,"20 21,22 captured will be between 12 and 13 and rest like http://regex101.com/r/rX0dM7/1 Now if i change the same the to (?!(.*?".*?")*[^"]*?$), This captures only the end ,'s between 18 and 19.Something like http://regex101.com/r/hL7uS1/1 Now the question is why is [^"] so different from .*?" . Secondly what is the significance of [^"]*$ as if i

Regular expression for SSN and phone number [closed]

对着背影说爱祢 提交于 2019-12-02 23:55:57
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . The string should not contain SSN or phone number. The regex below does not work, it accepts only xxxxxxxxx format. Should not contain xxx-xx-xxxx or xxx-xxx-xxx or xxxxxxxxx . regex = "^((?!\\d[9]$)|(?!(\\d{3}-?

How do I write a regex to match a string that doesn't contain a word? [duplicate]

不问归期 提交于 2019-12-02 17:07:39
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Regular expression to match string not containing a word? To not match a set of characters I would use e.g. [^\"\\r\\n]* Now I want to not match a fixed character set, e.g. "|=" In other words, I want to match: ( not ", not \r, not \n, and not |= ). EDIT: I am trying to modify the regex for parsing data separated with delimiters. The single-delimiter solution I got form a CSV parser, but now I want to expand it

Regular Expression block negation

巧了我就是萌 提交于 2019-12-02 16:15:20
问题 I want to find out a string in which a particular tag does not occur, such as: <xyz>[\w]+<[^(unwanted)]></xyz> where unwanted will be interpreted as a , d , e , n , t and u . But what I want is a block string. How can I express it in regular expression? I have tried negative lookahead, which doesn't work: <xyz>.+(?!unwanted).+</xyz> 回答1: <xyz>(?:(?!unwanted).)+</xyz> Matches all chars in <xyz>...</xyz> , but only as long as the expression unwanted doesn't start at any of them. 来源: https:/

Regular expression for SSN and phone number [closed]

给你一囗甜甜゛ 提交于 2019-12-02 13:44:51
The string should not contain SSN or phone number. The regex below does not work, it accepts only xxxxxxxxx format. Should not contain xxx-xx-xxxx or xxx-xxx-xxx or xxxxxxxxx . regex = "^((?!\\d[9]$)|(?!(\\d{3}-?\\d{2}-?\\d{4}$)|(?!(\\d{3}-?\\d{3}-?\\d{3})$)$"; You might try: ^(?!((\\d{9})|(\\d{3}-\\d{2}-\\d{4})|(\\d{3}-\\d{3}-\\d{3}))$).* To explain, if we read the query you provided: ^((?!\\d[9]$)|(?!(\\d{3}-?\\d{2}-?\\d{4}$)|(?!(\\d{3}-?\\d{3}-?\\d{3})$)$ We could read that: is not followed by xxxxxxxxx OR is not followed by xxx-xx-xxxx OR is not followed by xxx-xxx-xxx (in my version at

Capture , if between substring “”

时间秒杀一切 提交于 2019-12-02 13:09:24
(?!([^"]*"[^"]*")*[^"]*$), This captures , if it is between "".Lets say the test string is 1 2 3 4 , 5 6 7, 8 9 "10 11 12 , 13 14 15," 16,17,"18,19,"20 21,22 captured will be between 12 and 13 and rest like http://regex101.com/r/rX0dM7/1 Now if i change the same the to (?!(.*?".*?")*[^"]*?$), This captures only the end ,'s between 18 and 19.Something like http://regex101.com/r/hL7uS1/1 Now the question is why is [^"] so different from .*?" . Secondly what is the significance of [^"]*$ as if i remove it nothing gets captured. Conceptually, I think you are not thinking this correctly.

Converting a Regex Expression that works in Chrome to work in Firefox [duplicate]

和自甴很熟 提交于 2019-12-02 12:56:58
This question already has an answer here: Javascript: negative lookbehind equivalent? 13 answers I have this Regex Expression that works in chrome but doesn't not work in Firefox. SyntaxError: invalid regexp group It has something to do with lookbehinds and Firefox does not support these. I need this to work in Firefox can some one help me convert this so it works in Firefox and filters out the tags as well? return new RegExp(`(?!<|>|/|&amp|_)(?<!</?[^>]*|&[^;]*)(${term})`, 'gi'); }; searchTermsInArray.forEach(term => { if (term.length) { const regexp = this.regexpFormula(term); newQuestion

Regular Expression block negation

◇◆丶佛笑我妖孽 提交于 2019-12-02 08:45:24
I want to find out a string in which a particular tag does not occur, such as: <xyz>[\w]+<[^(unwanted)]></xyz> where unwanted will be interpreted as a , d , e , n , t and u . But what I want is a block string. How can I express it in regular expression? I have tried negative lookahead, which doesn't work: <xyz>.+(?!unwanted).+</xyz> <xyz>(?:(?!unwanted).)+</xyz> Matches all chars in <xyz>...</xyz> , but only as long as the expression unwanted doesn't start at any of them. 来源: https://stackoverflow.com/questions/14819125/regular-expression-block-negation

Negate match for word in the beginning of string in RE2 syntax?

ぐ巨炮叔叔 提交于 2019-12-02 05:37:46
问题 Let's say that I have following strings: mail to tel:+358123456 http://www.google.fi mailto:foo@bar.fi hello world telephone elephant penny link owl How can I find only strings that do not start with 'tel:', 'http://' and 'mailto:' in RE2 syntax? I've tried following with following syntax, but it filters out all of them: [^(https?://|tel:|mailto:)] edit: RE2 syntax does not support negative lookbehind/lookahead. 回答1: There is no drop-in workaround for the lack of negative lookbehind on RE2