regex-negation

python-re: How do I match an alpha character

我的未来我决定 提交于 2019-11-26 12:45:54
问题 How can I match an alpha character with a regular expression. I want a character that is in \\w but is not in \\d . I want it unicode compatible that\'s why I cannot use [a-zA-Z] . 回答1: Your first two sentences contradict each other. "in \w but is not in \d " includes underscore. I'm assuming from your third sentence that you don't want underscore. Using a Venn diagram on the back of an envelope helps. Let's look at what we DON'T want: (1) characters that are not matched by \w (i.e. don't

Regex - Does not contain certain Characters

折月煮酒 提交于 2019-11-26 08:48:56
问题 I need a regex to match if anywhere in a sentence there is NOT either < or >. If either < or > are in the string then it must return false. I had a partial success with this but only if my < > are at the beginning or end: (?!<|>).*$ I am using .Net if that makes a difference. Thanks for the help. 回答1: ^[^<>]+$ The caret in the character class ( [^ ) means match anything but, so this means, beginning of string, then one or more of anything except < and > , then the end of the string. 回答2: Here

RegEx to exclude a specific string constant [duplicate]

拥有回忆 提交于 2019-11-26 04:38:48
问题 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. 回答1: 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

Regex matching between two strings?

余生颓废 提交于 2019-11-26 03:59:41
问题 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

Regular expression to match a line that doesn&#39;t contain a word

元气小坏坏 提交于 2019-11-25 22:10:25
问题 I know it\'s possible to match a word and then reverse the matches using other tools (e.g. grep -v ). However, is it possible to match lines that do not contain a specific word, e.g. hede , using a regular expression? Input: hoho hihi haha hede Code: grep \"<Regex for \'doesn\'t contain hede\'>\" input Desired output: hoho hihi haha 回答1: The notion that regex doesn't support inverse matching is not entirely true. You can mimic this behavior by using negative look-arounds: ^((?!hede).)*$ The