negative-lookahead

Java regex: Negative lookahead

时光毁灭记忆、已成空白 提交于 2019-11-29 09:03:12
I'm trying to craft two regular expressions that will match URIs. These URIs are of the format: /foo/someVariableData and /foo/someVariableData/bar/someOtherVariableData I need two regexes. Each needs to match one but not the other. The regexes I originally came up with are: /foo/.+ and /foo/.+/bar/.+ respectively. I think the second regex is fine. It will only match the second string. The first regex, however, matches both. So, I started playing around (for the first time) with negative lookahead. I designed the regex /foo/.+(?!bar) and set up the following code to test it public static void

String negation using regular expressions

痞子三分冷 提交于 2019-11-28 06:45:43
Is it possible to do string negation in regular expressions? I need to match all strings that do not contain the string ".." . I know you can use ^[^\.]*$ to match all strings that do not contain "." but I need to match more than one character. I know I could simply match a string containing ".." and then negate the return value of the match to achieve the same result but I just wondered if it was possible. You can use negative lookaheads: ^(?!.*\.\.).*$ That causes the expression to not match if it can find a sequence of two periods anywhere in the string. ^(?:(?!\.\.).)*$ will only match if

Java regex: Negative lookahead

徘徊边缘 提交于 2019-11-28 02:43:40
问题 I'm trying to craft two regular expressions that will match URIs. These URIs are of the format: /foo/someVariableData and /foo/someVariableData/bar/someOtherVariableData I need two regexes. Each needs to match one but not the other. The regexes I originally came up with are: /foo/.+ and /foo/.+/bar/.+ respectively. I think the second regex is fine. It will only match the second string. The first regex, however, matches both. So, I started playing around (for the first time) with negative

String negation using regular expressions

爱⌒轻易说出口 提交于 2019-11-27 01:28:48
问题 Is it possible to do string negation in regular expressions? I need to match all strings that do not contain the string ".." . I know you can use ^[^\.]*$ to match all strings that do not contain "." but I need to match more than one character. I know I could simply match a string containing ".." and then negate the return value of the match to achieve the same result but I just wondered if it was possible. 回答1: You can use negative lookaheads: ^(?!.*\.\.).*$ That causes the expression to not

Regex to match all permutations of {1,2,3,4} without repetition

坚强是说给别人听的谎言 提交于 2019-11-26 19:06:48
I am implementing the following problem in ruby. Here's the pattern that I want : 1234, 1324, 1432, 1423, 2341 and so on i.e. the digits in the four digit number should be between [1-4] and should also be non-repetitive. to make you understand in a simple manner I take a two digit pattern and the solution should be : 12, 21 i.e. the digits should be either 1 or 2 and should be non-repetitive. To make sure that they are non-repetitive I want to use $1 for the condition for my second digit but its not working. Please help me out and thanks in advance. polygenelubricants You can use this ( see on

Regular expression negative lookahead

可紊 提交于 2019-11-26 14:28:20
In my home directory I have a folder drupal-6.14 that contains the Drupal platform. From this directory I use the following command: find drupal-6.14 -type f -iname '*' | grep -P 'drupal-6.14/(?!sites(?!/all|/default)).*' | xargs tar -czf drupal-6.14.tar.gz What this command does is gzips the folder drupal-6.14 , excluding all subfolders of drupal-6.14/sites/ except sites/all and sites/default , which it includes. My question is on the regular expression: grep -P 'drupal-6.14/(?!sites(?!/all|/default)).*' The expression works to exclude all the folders I want excluded, but I don't quite

Regular expression negative lookahead

China☆狼群 提交于 2019-11-26 03:55:38
问题 In my home directory I have a folder drupal-6.14 that contains the Drupal platform. From this directory I use the following command: find drupal-6.14 -type f -iname \'*\' | grep -P \'drupal-6.14/(?!sites(?!/all|/default)).*\' | xargs tar -czf drupal-6.14.tar.gz What this command does is gzips the folder drupal-6.14 , excluding all subfolders of drupal-6.14/sites/ except sites/all and sites/default , which it includes. My question is on the regular expression: grep -P \'drupal-6.14/(?!sites(?!