Regex for skipping specified URL extensions - regex

I have a link. Ex: http://my.domain/url.jsp
My goal is create patter that will be not allow any URLs with extension like this: .ex1, .ex2, .ex3
I was searching a long of time and find some approach, but it's really opposite that I want.
([^\s]+(\.(?i)(ex1|ex2|ex3))$)

If lookbehind is supported then this regex should work:
^\S+$(?<!\.(?:ex1|ex2|ex3)$)
Live Demo: http://www.rubular.com/r/gQDxYdDKcU
If lookbehind isn't supported (e.g. Javascript) then use this lookahead based regex:
^(?!.*?\.(?:ex1|ex2|ex3)$)\S+$
Live Demo: http://www.rubular.com/r/S0FGAETLr2

Related

Regex with exceptions to certain keywords

I am trying to create regex expression (to use with Stylish extension for Firefox) that will render true for every string that has youtube.com, however will render false if string contains /user/ or /channel/.
Example
True
https://www.youtube.com/feed/trending
False
https://www.youtube.com/user/whateva/featured
https://www.youtube.com/channel/lfjafjsldsf
I don't even know where to start, tried to learn regex several times, but its beyond my understanding how it works.
I believe this should do it:
^.*youtube\.com((?!\/user\/|\/channel\/).)*$
See live demo
Proposed solution is using negative lookahead. For more information on that see:
Regex tutorial on lookarounds
Regex lookahead, lookbehind and atomic groups

editpad regex. Searching files for "http://" but excluding "http://particular.domain.com"

I'm using RegexBuddy and getting nowhere defining a search parameter for editpad.
I'm trying to search through my CMS web site for all instances of "http://" (to see where the protocol was hardcoded incorrectly), but every file has "http://particular.domain.com" in the comments near the top of the file.
How can I search for all EXCEPT those? This seems like it should be basic.
Here's your expression:
http:\/\/(?!particular\.domain\.com).+
Check out a demo here: https://regex101.com/r/eT2cX8/2
This portion is called a negative lookahead that lets you negate that match:
(?!particular\.domain\.com).+
use a negative lookahead:
'(?!http://particular.domain.com)http://'
is an example of a pattern that would match any http:// text EXCEPT the particular one

Regular expression not working in google analytics

Im trying to build a regular expression to capture URLs which contain a certain parameter 7136D38A-AA70-434E-A705-0F5C6D072A3B
Ive set up a simple regex to capture a URL with anything before and anything after this parameter (just just all URLs which contain this parameter). Ive tested this on an online checker: http://scriptular.com/ and seems to work fine. However google analytics is saying this is invalid when i try to use it. Any idea what is causing this?
Url will be in the format
/home/index?x=23908123890123&y=kjdfhjhsfd&z=7136D38A-AA70-434E-A705-0F5C6D072A3B&p=kljdaslkjasd
so i just want to capture URLs that contain that specific "z" parameter.
regex
^.+(?=7136D38A-AA70-434E-A705-0F5C6D072A3B).+$
You just need
^.+=7136D38A-AA70-434E-A705-0F5C6D072A3B.+$
Or (a bit safer):
^.+=7136D38A-AA70-434E-A705-0F5C6D072A3B($|&.+$)
And I think you can even use
=7136D38A-AA70-434E-A705-0F5C6D072A3B($|&)
See demo
Your regex is invalid because GA regex flavor does not support look-arounds (and you have a (?=...) positive look-ahead in yours).
Here is a good GA regex cheatsheet.
To match /home/index?x=23908123890123&y=kjdfhjhsfd&z=7136D38A-AA70-434E-A705-0F5C6D072A3B&p=kljdaslkjasd you can use:
\S*7136D38A-AA70-434E-A705-0F5C6D072A3B\S*

How to write a twitter regex expression?

I need a twitter expression:
twitter.com\/[\w\/\.=-]*
This one works fine, except it does capture generic twitter widgets.js library
I would like to capture ALL twitter.com EXCEPT those who cantain "widgets.js" (using regex)
ex:
twitter.com/myaccount: GOOD
twitter.com/JohnDOes: GOOD
twitter.com/widgets.js: BAD
Regards
You can do this with a negative lookahead:
twitter.com\/(?!widgets\.js)[\w\/\.=-]*
Depending on whether you are matching part of a larger text or individual strings, you may want to add some anchors:
^twitter.com\/(?!widgets\.js$)[\w\/\.=-]*$

REGEX: excluding a string from a pattern that is already excluding particular characters

I'm trying to write a regular expression to use to validate a url path. We orginally had the pattern: [^#\?:]+ which would grab everything up until the first ?, : or # from the path.
We now want to also exclude the string 'index.cfm'.
I can't work out how to include this though. I've had a look at lookarounds but I can't seem to work out how to use it in conjunction with the pattern we already have.
EDIT: Here's an edited solution according to your comment.
^.*?(?=[#?:]|index\.cfm|$)
Here's a demo using the site you mentioned: http://regexr.com?31rk9.
should work for you
^(?P<url>[^#?:](?!index\.cfm))+