Regular expression for any domain followed by a folder - regex

I have the following regular expression which basically returns .domain.com/
^[0-9a-zA-Z_\-.]{1,256}\.domain\.com/
I am looking to change the expression so that it returns any domain with a dot com extension that is followed by /js can anyone tell me how I can do this?
Thanks

You can try the following:
(?:http:\/\/)(.*?\.com(?=\/js\/))
If you can tell your regex processor to return capture group #1, you'll get any domain preceded by http:// and followed by /js/.
Otherwise (i.e. using this expression as a stand-alone), you'll get the domain including the http://.

Try this one:
^([\w\d_\-]+[\.]?[\w\d\-_]+)+\.com\/js$

Related

Extract domain from email address with Regex

I'm learning regular expressions and I'm having trouble extracting the domain from the email address. I have an email address: example#gmail.com. I need to use a regular expression to extract #gmail (along with the # symbol). I should end up only getting example. I've already tried this:
your text#(\w+)
and this
your text(?<=#)[^.]+(?=.).*
but those expressions didn't work properly. I'd appreciate your help.
I just tried a simple look behind - #(?<=#).* it will match #google.com you can also group the entire expression and can change it according to single and multi-line matches.
#(?<=#).*

Regular expression to find last dot in request URI

I am trying to write a regular expression for apache virtual host configuration that will map request if URI doesn't have certain extensions. Below expression I have written.
^\/bookdata\/.+\.(?!jpg|mp3|mp4|zip|doc|pdf|xls|xlsx).*$
Below URI is not matching to this expression which is perfectly fine.
/bookdata/rw0/media/Q2e_00_RW_U08_Q_Classroom.mp3?fd=1
My problem with below URI which is matching with this expression due to two dots.
/bookdata/rw0/media/ELM2_U02_Track06_Chart2.8.mp3?fd=1
Any small help will be appreciated.
Put the neg. lookahead right at the start, like so
^(?!.*\.(?:jpg|mp3|mp4|zip|doc|pdf|xls|xlsx))\/bookdata\/.+$
See a demo on regex101.com.
As I know request URI doesn't contain request params(after question mark)
So you can ommit .* at the end of your regex then you can match your prefer uris.
This happen because you say that your uri end by those extension must not match.

Regular expression to match a domain

I want to have a regular Expression for Google Analytic so I can match all the domain including the sub domains
say we have to match a domain name called xyz.com
So i want to match every url that have xyz.com in it.
Example
abcd.xyz.com, abc1232.xyz, www.xyz.com, www.xyz.com/abc
Can anyone help me with that.
My purpose to it to have the traafic reports excluded in Google Analytics that are coming from these sites.
In general, the regular expression to match those domains would be something like .*\.xyz\.com$. The backslashes escape the dots (which are normally wildcard characters and the dollar-sign represents the end of the string.
There are different regex implementations, so you might have to tweak this for your regex engine.
To exclude subdomains like described above you can use GA filter([Exclude] [Hostname] [Matching RegEx]) along with regular expression (xyz.com)|(.*.xyz.com).
This RegEx including both main domain and it's subdomains.
You could try this regex
(.*\.)?xyz\.com
This matches all your required formats for the URL.

regular expression of this url

I need regular expression of url such as below
http://www.aparat.com/v/bqn5H
http://www.aparat.com/v/raozG
http://www.aparat.com/v/wKZOY
http://www.aparat.com/v/noopj
I wrote one but I think it doesn't work
http:\/\/www\.aparat\.com\/v\/([a-zA-Z0-9-_]+)
Your regex is correct. I think you are forgetting the g modifier.
See here: http://regex101.com/r/tJ1wR5
Also see: What is the best regular expression to check if a string is a valid URL?
Works fine with using the word (\w) with one or more quantifier
http:\/\/www\.aparat\.com\/v\/\w+
I checked my code and I found that this is not exactly what I need.
this is the best fit regular expression:
http:\/\/www\.aparat\.com\/v\/.*([a-z0-9-_]+)
The following code supports
http and https
www and without www
code:
^((?:https?:)?\/\/)?((?:www|m)\.)?((?:aparat(-nocookie)?\.com))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$
https://regex101.com/r/y5atof/1

Regex Expression to Match URL and Exclude Other

Im trying to write a regex expression to match anything (.*)/feed/ with the exception of (.*)/author/feed/
Currently, I have (.*)/feed/(.*) which works well to identify any string /feed/ to redirect. However, I dont want to exlude those that have /author/(.*)/feed/
For example - match http://www.site.com/ANYTHING/feed/ but exclude site.com/author/ANYTHING/feed/
I should clarify that I'm not terribly familiar with regex expressions but this is actually for use within the Redirection plugin for wordpress which states "Full regular expression support."
Any help would be greatly appreciated. Thank you in advance
Depending on the language, you may be able to use a negative look-behind assertion:
(.*)(?<!/author)/feed
The assertion, (?<!/author), ensures that /author does not match behind the text /feed, but does not count it as being matched.