Regular expression for a string containing one word but not another

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 selector=size but does NOT contain details.cfm

I know that to find a string that does NOT contain another string I can use this expression:

(^((?!details.cfm).)*$)

But, I’m not sure how to add in the selector=size portion.

Any help would be greatly appreciated!

Regular expression containing one word or another

I need to create an expression matching a whole number followed by either seconds or minutes I tried this expression: ([0-9]+)/s+(/bseconds/b)|(/bminutes/b) It works fine for seconds, but not min

Regular expression to match string not containing a word?

I know it is possible to match for the word and using tools options reverse the match. (eg. by grep -v) However I want to know if it is possible using regular expressions to match lines which does not

Regular expression to match string not containing a word?

I know it is possible to match for the word and using tools options reverse the match. (eg. by grep -v) However I want to know if it is possible using regular expressions to match lines which does not

Exclude one regular expression from another regular expression

In JavaScript, is it possible to exclude matches of one regular expression (by writing another regular expression)? For example, I’d like to exclude all matches of the regular expression /(cl|g|cr|d)(

Regular expression to remove last word in a string?

I have a string like this 87 CAMBRIDGE PARK DR.I have used the below regular expression to remove the last word DR, but it also removing the word PARK also.. Below is my code… String regex =

Help With Particular Regular Expression – Not Containing Some String

How do I say, in regular expressions: Any portion of a string beginning with a capital letter, containing at least one space character, not containing the string _ (space underscore space), and en

Efficient way to find the token (word) index after a regular expression string search

I need to perform a regular expression search for a string x in another string y, but I then need to know the token (word) index of the first character of the hit after tokenizing (splitting) string y

Python Regex: Picking one regular expression OR another

I am trying to create a regular expression that chooses to use one regex or another – depening on the input. Here is a simplified version on what my regex looks like: string = ’78 east easy street Ne

str.split() pass muliple delimeter one regular expression and another string

Well I am using var str.split() in javascript to pass multiple delimeter where one is regular express and another is string where regular expresion is //([0-9]/)/ and string is Exception. How to pass

Regular expression or function to search for word and return the next one

I’m looking for a function/regular expression that finds the given word and retruns the next one for example: Giving the input is and searching in this string the force is strong with you but you

Answers

This should do it:

^(?!.*details/.cfm).*selector=size.*$

^.*selector=size.*$ should be clear enough. The first bit, (?!.*details.cfm) is a negative look-ahead: before matching the string it checks the string does not contain “details.cfm” (with any number of characters before it).

^(?=.*selector=size)(?:(?!details/.cfm).)+$

If your regex engine supported posessive quantifiers (though I suspect Google Analytics does not), then I guess this will perform better for large input sets:

^[^?]*+(?<!details/.cfm).*?selector=size.*$

regex could be (perl syntax):

`/^[(^(?!.*details/.cfm).*selector=size.*)|(selector=size.*^(?!.*details/.cfm).*)]$/`

Simple way to do this is to specify 0 instances of the string by doing the following

(string_to_exclude){0}

I was looking for a way to avoid –line-buffered on a tail in a similar situation as the OP and Kobi’s solution works great for me. In my case excluding lines with either “bot” or “spider” while including ‘ / ‘ (for my root document).

My original command:

tail -f mylogfile | grep --line-buffered -v 'bot/|spider' | grep ' / '

Now becomes (with “-P” perl switch):

tail -f mylogfile | grep -P '^(?!.*(bot|spider)).*/s///s.*$'