regex-negation

Extract text and links from HTML using Regular Expressions

本小妞迷上赌 提交于 2019-11-28 06:39:41
问题 I would like to extract text from an html document keeping the links inside it. for example: From this HTML code <div class="CssClass21">bla1 bla1 bla1 <a href="http://www.ibrii.com">go to ibrii</a> bla2 bla2 bla2 <img src="http://www.contoso.com/hello.jpg"> <span class="cssClass34">hello hello</span> I would like to extract just this bla1 bla1 bla1 <a href="http://www.ibrii.com">go to ibrii</a> bla2 bla2 bla2 hello hello In another post on StackOverflow i have found the RegEx <[^>]*> which

Notepad++ use both regular expressions and extended search

╄→尐↘猪︶ㄣ 提交于 2019-11-28 06:30:04
问题 I need to find all \r\n that do not precede the letter M; Seems I can't do this: \r\n[^M] I can only do \r\n with extended search selected or [^M] with regular expressions selected; but not together. 回答1: You should instead use this regex: \R(?!M) Explanation: \R Any Unicode newline sequence. (?!M) Negative Lookahead : Assert "M" cannot be matched. 回答2: \r\n is valid with Regular expression checked in the Find tab too - i.e. not just with Extended checked: why not just use \r\n[^M] with

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

给你一囗甜甜゛ 提交于 2019-11-27 21:27:07
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 " 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 if viewed as a function, I suppose you could say that the inverse of the matcher is the generator which

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

筅森魡賤 提交于 2019-11-27 20:59:27
I need a single-pass regex for unix grep that contains, say alpha, but does not contain beta. grep 'alpha' <> | grep -v 'beta' ^((?!beta).)*alpha((?!beta).)*$ would do the trick I think. 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 expressions using the boolean logic of whatever language you are using. If you’re using the grep command at a unix shell

Regex to match anything but two words

空扰寡人 提交于 2019-11-27 20:02:30
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. Tim Pietzcker Answer to the question: "A Regular Expression to match anything that isn't "foo" and "bar"?" ^(?!foo$|bar$).* would do exactly that. ^ # Start of string (?! # Assert that it's

RegEx for no whitespace at the beginning and end

南楼画角 提交于 2019-11-27 18:24:23
问题 I want to design an expression for not allowing whitespace at the beginning and at the end of a string, but allowing in the middle of the string. The regex I've tried is this: \^[^\s][a-z\sA-Z\s0-9\s-()][^\s$]\ 回答1: This should work: ^[^\s]+(\s+[^\s]+)*$ If you want to include character restrictions: ^[-a-zA-Z0-9-()]+(\s+[-a-zA-Z0-9-()]+)*$ Explanation: the starting ^ and ending $ denotes the string. considering the first regex I gave, [^\s]+ means at least one not whitespace and \s+ means at

Negate characters in Regular Expression

狂风中的少年 提交于 2019-11-27 14:34:39
How would I write a regular expression that matches the following criteria? No numbers No special characters No spaces in a string 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 whitespace (space, tab, carriage return, line feed) \d - matches 0-9 Or you can take another approach by simply

How To Negate Regex [duplicate]

浪尽此生 提交于 2019-11-27 14:26:20
问题 Possible Duplicate: Regular expression to match string not containing a word? How can I invert a regular expression in JavaScript? Say I have the regex foo123 . How do I match everything that is not foo123 ? 回答1: Use negative lookahead for this. (?!foo123).+ matches any string except foo123 If you want to match empty string also, use (?!foo123).* In your case (according to the comment) the required regex is (?!P[0-9]{1,}).+ . It matches P and 123 , but not P123 . 来源: https://stackoverflow.com

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

一笑奈何 提交于 2019-11-27 14:00: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? You can try a negative lookahead, avoiding the start of the string: /(?!^)l/g See if online: jsfiddle Rob W There's no JS RegExp to replace everything-but-the-first-pattern-match. You can, however, implement this behaviour by passing a function as a second argument to the replace

RegExp matching string not starting with my

只谈情不闲聊 提交于 2019-11-27 10:36:07
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. You could either use a lookahead assertion like others have suggested. Or, if you just want to use basic regular