regex-negation

Help with regex include and exclude

帅比萌擦擦* 提交于 2019-12-18 13:14:28
问题 I would like some help with regex. I'm trying to create an expression that will include certain strings and exclude certain strings. For example: I would like to include any URL containing mobility http://www.something.com/mobility/ However I would like to exclude any URL containing store http://www.something.com/store/mobility/ FYI I have many keywords that I'm using to include. Currently I am including like this /mobility|enterprise|products/i however I am not finding it able to exclude

Regex Match Ampersand but not escaped xml characters

杀马特。学长 韩版系。学妹 提交于 2019-12-18 04:33:05
问题 I would like to match ampersand (&) but not when it exists in following manner &apos; " > < & &# So in the following line & MY& NAME IS M&Hh. &apos; " > < & &# &&&&&& I want it to match all ampersands except those which exist in &apos; " > < & &# 回答1: That looks like a job for negative lookahead assertions: &(?!(?:apos|quot|[gl]t|amp);|#) should work. Explanation: & # Match & (?! # only if it's not followed by (?: # either apos # apos |quot # or quot |[gl]t # or gt/lt |amp # or amp ); # and a

Regex - match anything except specific string

自古美人都是妖i 提交于 2019-12-18 04:04:28
问题 I need a regex (will be used in ZF2 routing, I believe it uses the preg_match of php) that matches anything except a specific string. For example: I need to match anything except "red", "green" or "blue". I currently have the regex: ^(?!red|green|blue).*$ test -> match (correct) testred -> match (correct) red -> doesn't match (correct) redtest -> doesn't match (incorrect) In the last case, the regex is not behaving like I want. It should match "redtest" because "redtest" is not ("red", "green

Negating a set of words via java regex

被刻印的时光 ゝ 提交于 2019-12-17 23:17:23
问题 I would like to negate a set of words using java regex. Say, I want to negate cvs , svn , nvs , mvc . I wrote a regex which is ^[(svn|cvs|nvs|mvc)] . Some how that seems not to be working. 回答1: Try this: ^(?!.*(svn|cvs|nvs|mvc)).*$ this will match text if it doesn't contain one of svn, cvs, nvs or mvc. This is a similar question: C# Regex to match a string that doesn't contain a certain string? 回答2: It's not that simple. If you want to negate a word you have to split it to letters and negate

Regular expression pattern to match string without any 2 consecutive repeated characters

大城市里の小女人 提交于 2019-12-17 20:28:05
问题 I can very easily write a regular expression to match a string that contains 2 consecutive repeated characters: /(\w)\1/ How do I do the complement of that? I want to match strings that don't have 2 consecutive repeated characters. I've tried variations of the following without success: /(\w)[^\1]/ ;doesn't work as hoped /(?!(\w)\1)/ ;looks ahead, but some portion of the string will match /(\w)(?!\1)/ ;again, some portion of the string will match I don't want any language/platform specific

JSLint “insecure ^” in regular expression

我的未来我决定 提交于 2019-12-17 06:49:22
问题 JSLint reports Insecure '^' for the following line. Why is that? Or is it just going to complain any time I want to negate a character class? // remove all non alphanumeric, comma and dash characters "!$7s-gd,&j5d-a#".replace(/[^\w,\-]/g, ''); 回答1: It only will do this if you have the option selected at the bottom: Disallow insecure . and [^...] in /RegExp/ From the docs: true if . and [^...] should not be allowed in RegExp literals. These forms should not be used when validating in secure

Regular expression that doesn't contain certain string [duplicate]

℡╲_俬逩灬. 提交于 2019-12-17 02:43:14
问题 This question already has answers here : Regular expression to match a line that doesn't contain a word (29 answers) Closed 2 years ago . I have something like this aabbabcaabda for selecting minimal group wrapped by a I have this /a([^a]*)a/ which works just fine But i have problem with groups wrapped by aa , where I'd need something like /aa([^aa]*)aa/ which doesn't work, and I can't use the first one like /aa([^a]*)aa/ , because it would end on first occurence of a , which I don't want.

How to negate the whole regex?

拜拜、爱过 提交于 2019-12-16 22:11:08
问题 I have a regex, for example (ma|(t){1}) . It matches ma and t and doesn't match bla . I want to negate the regex, thus it must match bla and not ma and t , by adding something to this regex . I know I can write bla , the actual regex is however more complex. 回答1: Use negative lookaround: (?! pattern ) Positive lookarounds can be used to assert that a pattern matches. Negative lookarounds is the opposite: it's used to assert that a pattern DOES NOT match. Some flavor supports assertions; some

Regular expression for a string containing one word but not another

牧云@^-^@ 提交于 2019-12-16 19:46:11
问题 I'm setting up some goals in Google Analytics and could use a little regex help. Lets say I have 4 URLs http://www.anydotcom.com/test/search.cfm?metric=blah&selector=size&value=1 http://www.anydotcom.com/test/search.cfm?metric=blah2&selector=style&value=1 http://www.anydotcom.com/test/search.cfm?metric=blah3&selector=size&value=1 http://www.anydotcom.com/test/details.cfm?metric=blah&selector=size&value=1 I want to create an expression that will identify any URL that contains the string

Notepad++ how to extract only the text field which is needed?

爱⌒轻易说出口 提交于 2019-12-13 20:12:26
问题 I have a log file which has lot of data. But it would be in similar format. Sample text: Line 1428: [errormessage] = 21:26:07.629 acceptance criteria not met. Expected:0.0009999871, Actual:0.007407427, Window:[0.007407427] at Hello.TestAutomation.Tests.Implementation.TestExecution.MirrorTestExecutor.b__12_1(IMonitor m, MonitoringEventArgs e) Line 1429: [errormessage] = 21:26:07.629 acceptance criteria not met. Expected:0.0009999871, Actual:0.007407427, Window:[0.007407787] at Hello