Regular expression to exclude part of a url? - regex

I'm trying to create a regular expression for google analytics goals.
I need to match either of these 2 url fragments:
/order/map/egw/?code=somevalue
or
/order/map/egw/
But NOT this url:
/order/map/egw/consult/
Tried this:
/order/map/egw/$ | /order/map/egw/\?
and other variations but can't get it to match properly
Fast help greatly appreciated!

How about this regular expression?
/order/map/egw/(?!consult).*
If in the future you find that there's another sub-directory that you don't want to include, you can add a new one (e.g. the sub-directory 'wrong') like so:
/order/map/egw/(?!consult|wrong).*

What about this? I don't know how strict you're trying to be but it should work for your use cases:
(?!.*consult)/order/map/egw/(\?.+)?
It ensures "consult" is not found in the URL and matches the base part with an optional query string.

Related

Regular expression to check path of url as well as specific parameters

I have url's like the following:
/home/lead/statusupdate.php?callback=jQuery211010657244874164462_1455536082020&ref=e13ec8e3-99a8-411c-be50-7e57991d7acb&status=5&_=1455536082021
I would like a regular expression to use in my Google analytic goal that checks to see that the request uri is /home/lead/statusupdate.php and has ref and status parameter present regardless of what order these parameters are passed and regardless of if there are extra parameters because I really just care about the 2. I have looked at these examples
How to say in RegExp "contain this too"? and Regular Expressions: Is there an AND operator? but I can't seem to adapt the examples given there to work.
Im using this online tool to test http://www.regexr.com/ (perhaps the tool is the buggy one? I'l try in javascript in the mean time)
You can try:
\/home\/lead\/statusupdate\.php\?(ref=|.*(&ref=)).*(&status=)
if the order does not matter, then add the oppostite
\/home\/lead\/statusupdate\.php\?(status=|.*(&status=)).*(&ref=)
all put together
\/home\/lead\/statusupdate\.php\?(((ref=|.*(&ref=)).*(&status=))|((status=|.*(&status=)).*(&ref=)))
try:
(/home/lead/statusupdate.php?A)|(/home/lead/statusupdate.php?B)|(/home/lead/statusupdate.php?C)|(/home/lead/statusupdate.php?D)|(/home/lead/statusupdate.php?E)|(/home/lead/statusupdate.php?F)
Note that here A,B,C,D,E,F are notations for six different permutations for 'callback' string, 'ref' string, 'status' string and '_' string.
Not really elegant but this works:
\/home\/lead\/statusupdate\.php(.*(ref|status)){2}
Looks for /home/lad/statusupdate.php followed by 2x any character followed by ref or status. Admittedly this would be a match for an url with 2x ref or status though.
Demo

Perl/lighttpd regex

I'm using regex in lighttpd to rewrite URLs, but I can't write an expression that does what I want (which I thought was pretty basic, apparently not, I'm probably missing something).
Say I have this URL: /page/variable_to_pass/ OR /page/variable_to_pass/
I want to rewrite the URL to this: /page.php?var=variable_to_pass
I've already got rules like ^/login/(.*?)$ to handle specific pages, but I wanted to make one that can match any page without needing one expression per page.
I tried this: ^/([^.?]*) but it matches the whole /page/variable_to_pass/ instead of just page.
Any help is appreciated, thanks!
This regexp should do what you need
/([^\/]+)/(.+)
First match would be page name, and the second - variable value
Try:
/([^.?])+/([^.?])+/
That should give you two matches.

simple regular expression - match specific url

I'm a noob when it comes to Regular Expressions. I'm using Joomla and the Advanced Module Manager to publish a module to a specific url.
I want to publish a module only to the url /tv-show and not /tv-show/anthingthing-else/blahblah
I thought the way to do it is /tv-show* but obviously not, since it still publishes to other urls with /tv-show on the beginning.
I tried many variations, please tell me where am I going wrong?
Try the following
/tv-show$
The dollar matches the end of a string.

Flickr photo URL replacement regular expression

I'm trying to write a regular expression to modify URLs stored in a database (linking to photos on Flickr) so I can change the size of photos already on a site -
E.g. Replace: 4724575242_ca7d120609.jpg with 4724575242_ca7d120609_z.jpg in a URL such as:
http://farm2.static.flickr.com/1045/4724575242_ca7d120609.jpg
The only change is to add _z before the .jpg extension.
I imagined that a regular expression could be written which matches static.flickr.com then replace .jpg with _z.jpg but unfortunately my attempts have so far failed.
I wondered if any regex ninjas out there might be able to help me with this?
Any help would be greatly appreciated - David
Maybe this one (adapting it to your language, of course) ?
/static\.flickr\.com\/([a-z0-9_\/]+)\.jpg$/static.flickr.com\/$1_z.jpg/

Regex mid-string pattern exclustion

I need help with a regular expression for use with UrlRewriting.Net. I have two URLs -
http://domain/SomeFolder/tracks/SomeFileName/
and
http://domain/SomeFolder/<could be anything>/SomeFileName/
For URL rewriting purposes I need to come up with one expression that will let me target specifically the URL with "tracks" in the middle of it. I need another expression to catch everything without "tracks" in it.
Before I had this constraint I was using ^~/SomeFolder/([^/]*)/SomeFileName/?$ and that worked as my catch-all. Now that I have this specific "tracks" folder, I can't use the catch all.
Make sense?
Many thanks for the help!
^~/SomeFolder/(?!tracks/)([^/]*)/SomeFileName/?$
and
^~/SomeFolder/(tracks)/SomeFileName/?$