regex-negation

JavaScript regex for blacklisting words [duplicate]

耗尽温柔 提交于 2019-12-22 13:56:12
问题 This question already has answers here : Regex: match everything but specific pattern (7 answers) Closed 2 years ago . I'm trying to write a regex to blacklist certain words. I'm able to create a whitelist like /^(carrots|onions|corn)$/ but how would I convert that into a blacklist? Edit: To clarify, I'm matching this blacklist against a whole string. For example "corndog" should be allowed. I want the regex equivalent of blacklistArray.indexOf(word) === -1 回答1: Use negative lookahead: ^(?!.*

Regex that says what NOT to match?

Deadly 提交于 2019-12-22 12:37:17
问题 I’m wondering how to match any characters except for a particular string (call it "for" ) in a regex. I was thinking maybe it was something like this: [^for]* — except that that doesn’t work. 回答1: I’m sure this a dup. One way is to start your pattern with a lookahead like this: (?=\A(?s:(?!for).)*\z) That can be written like this in any regex system worth bothering with: (?x) # turn /x mode on for commentary & spacing (?= # lookahead assertion; hence nonconsumptive \A # beginning of string (

How would you use a regular expression to ignore strings that contain a specific substring?

戏子无情 提交于 2019-12-22 08:08:06
问题 How would I go about using a negative lookbehind(or any other method) regular expression to ignore strings that contains a specific substring? I've read two previous stackoverflow questions: java-regexp-for-file-filtering regex-to-match-against-something-that-is-not-a-specific-substring They are nearly what I want... my problem is the string doesn't end with what I want to ignore. If it did this would not be a problem. I have a feeling this has to do with the fact that lookarounds are zero

Python regex not to match http://

给你一囗甜甜゛ 提交于 2019-12-21 12:23:52
问题 I am facing a problem to match and replace certain words, not contained in http:// Present Regex: http://.*?\s+ This matches the pattern http://www.egg1.com http://www.egg2.com I need a regex to match certain words contained outside the http:// Example: "This is a sample. http://www.egg1.com and http://egg2.com. This regex will only match this egg1 and egg2 and not the others contained inside http:// " Match: egg1 egg2 Replaced: replaced1 replaced2 Final Output : "This is a sample. http://www

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

做~自己de王妃 提交于 2019-12-20 07:56:04
问题 This question already has answers here : Javascript: negative lookbehind equivalent? (13 answers) Closed 6 months ago . 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

Matching patterns in Python

折月煮酒 提交于 2019-12-20 03:45:09
问题 I have an XML file which contains the following strings: <field name="id">abcdef</field> <field name="intro" > pqrst</field> <field name="desc"> this is a test file. We will show 5>2 and 3<5 and try to remove non xml compatible characters.</field> In the body of the XML, I have > and < characters, which are not compatible with the XML specification. I need to replace them such that when > and < are in: ' "> ' ' " > ' and ' </ ' respectively, they should NOT be replaced, all other occurrence

replace characters in notepad++ BUT exclude characters inside single quotation marks

空扰寡人 提交于 2019-12-20 02:54:16
问题 I have a string in this kind: SELECT column_name FROM table_name WHERE column_name IN ('A' , 'stu' ,'Meyer', ....); I want replace all characters in notepad++ from upper to lower (or vice versa) BUT, exclude from replacement, characters inside single quotation marks. condition: It exists no solid structure before/behind the single quotation marks part! (That means - I can not use the keyword "IN" or signs like "," or "(" or ")" or ";" for this regex ...!) target string (the characters inside

Regex to match a whole string only if it lacks a given substring/suffix

老子叫甜甜 提交于 2019-12-19 05:52:57
问题 I've searched for questions like this, but all the cases I found were solved in a problem-specific manner, like using !g in vi to negate the regex matches, or matching other things, without a regex negation. Thus, I'm interested in a “pure” solution to this: Having a set of strings I need to filter them with a regular expression matcher so that it only leaves (matches) the strings lacking a given substring. For example, filtering out "Foo" in: Boo Foo Bar FooBar BooFooBar Baz Would result in:

How can I find everything BUT certain phrases with a regular expression?

孤街浪徒 提交于 2019-12-19 04:32:11
问题 Ok, so I have a phrase "foo bar" and I want to find everything BUT "foo bar". Here's my text. ipsum dolor foo bar Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor foo bar incididunt ut labore et dolore foo bar There's a way to do this just within regex right? I don't have to go and use strings etc. do I? RESULT: NOTE I can't do a nice highlighting but the bold gives you an idea (although the spaces that are before and after would also be selected but it breaks

How to match every file but one in grunt concat?

余生长醉 提交于 2019-12-18 14:05:11
问题 I'm using grunt to concatenate and minimize my js files, I use the following config for the concat part: concat: { dist: { src: ['<banner:meta.banner>', 'js/*.js'], dest: 'js/script.js' } } It matches every file in my js folder but I need to ignore modernizr.js , is there a way to do this? I assume I'd need some pattern matching voodoo to do it but I'm not sure how. Thanks in advance. 回答1: Based on documentation I would try: js/!(modernizr).js (js/)!(modernizr).js {js/}!(modernizr).js js/!(