I am trying to write a regular expression in which I want to compare the URL's.
Any URL Matches
http://*.xyz.com
Except or Excluding
http://m.xyz.com and http://m.product.xyz.com
So far I was trying to do it by using if else in RegExp but I couldn't be able to do it right...
(^http:\/\/)(((1)<!(m|m\.product))\.xyz\.co\.jp)?
You can try that:
^http:\/\/(?!m\.xyz\.com|m\.product\.xyz\.com).*\.xyz\.com$
Regex101 Demo
https?:\/\/(?!m\.|m\.product\.).*\.xyz\..*
This regex accepts all *.xyz.* domains except m.xyz.* and m.product.xyz.*. Also takes care of http or https.
Demo
Related
I have response body which contains
"<h3 class="panel-title">Welcome
First Last </h3>"
I want to fetch 'First Last' as a output
The regular expression I have tried are
"Welcome(\s*([A-Za-z]+))(\s*([A-Za-z]+))"
"Welcome \s*([A-Za-z]+)\s*([A-Za-z]+)"
But not able to get the result. If I remove the newline and take it as
"<h3 class="panel-title">Welcome First Last </h3>" it is detecting in online regex maker.
I suspect your problem is the carriage return between "Welcome" and the user name. If you use the "single-line mode" flag (?s) in your regex, it will ignore newlines. Try these:
(?s)Welcome(\s*([A-Za-z]+))(\s*([A-Za-z]+))
(?s)Welcome \s*([A-Za-z]+)\s*([A-Za-z]+)
(this works in jMeter and any other java or php based regex, but not in javascript. In the comments on the question you say you're using javascript and also jMeter - if it is a jMeter question, then this will help. if javaScript, try one of the other answers)
Well, usually I don't recommend regex for this kind of work. DOM manipulation plays at its best.
but you can use following regex to yank text:
/(?:<h3.*?>)([^<]+)(?:<\/h3>)/i
See demo at https://regex101.com/r/wA2sZ9/1
This will extract First and Last names including extra spacing. I'm sure you can easily deal with spaces.
In jmeter reg exp extractor you can use:
<h3 class="panel-title">Welcome(.*?)</h3>
Then take value using $1$.
In the data you shown welcome is followed by enter.If actually its part of response then you have to use \n.
<h3 class="panel-title">Welcome\n(.*?)</h3>
Otherwise above one is enough.
First verify this in jmeter using regular expression tester of response body.
Welcome([\s\S]+?)<
Try this, it will definitely work.
Regular expressions are greedy by default, try this
Welcome\s*([A-Za-z]+)\s*([A-Za-z]+)
Groups 1 and 2 contain your data
Check it here
I'm trying to get a regular expression to work where the following URLs are accepted:
www.somesite.com
somesite.com
www.somesite.ca
somesite.ca
somesite.cu.sk.ca
www.somsite.cu.sk.ca
somesite.sk.ca
www.somesite.sk.ca
I have the following so far but it allows www.somesite
^(www\.)?[a-zA-Z0-9_\-]+\.([a-zA-Z]{2,4}|[a-zA-Z]{2}.[a-zA-Z]{2})(.[a-zA-z]{2})?$
Query strings, http, https, ftp are not in play here. Thanks!
You forgot to escape . in the last pattern (.[a-zA-z]{2}) (the dot will match any character):
^(www\.)?[\w-]+\.([a-zA-Z]{2,4}|[a-zA-Z]{2}.[a-zA-Z]{2})(\.[a-zA-z]{2})?$
↑
See DEMO
Also, I replaced your [a-zA-Z0-9_\-] with its equivalent [\w-]
I need a regular expression to match the following domains as follows:
http://www.cnn.com/fred = www.cnn.com
cnn.com = cnn.com
www.cnn.com:8080 = www.cnn.com
I have the following regular expression (using pcre):
([^/]+://)?([^:/]+)
The above works fine in case 2 and 3 however with 1 i still have the http:// appended to the matching string, is there a regular expression option which i can use to skip the http part?
many thanks in advance
This one should suit your needs:
^(?:(?:f|ht)tps?://)?([^/:]+)
The first group will contain what you're looking for.
this looks like the closest i could get to what i want not perfect but seems to gets the job done
www?([^/:]+)
I have the following regex that attempts to match URLs:
/((http|https):(([A-Za-z0-9$_.+!*(),;/?:#&~=-])|%[A-Fa-f0-9]{2}){2,}(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*(),;/?:#&~=%-]*))?([A-Za-z0-9$_+!*();/?:~-]))/g
How can I modify this regex to only match URLs of a single domain?
For example, I only want to match URLs that begin with http://www.google.com?
This should simplify my regex, but I'm too much of a regex noob to get it working (after all these years...)
Did you write that RegEx? I don't know what it's trying to do, but it certainly doesn't match URLs correctly. Here's something it matches:
http:###9#?~
which I'm pretty sure isn't a valid URL.
You shouldn't be using RegEx to match URLs like this. You haven't said what language you're working in, but use whatever its equivalent of urlparse is..
Here's a relevant question: How do you validate a URL with a regular expression in Python?
I am new to regular expressions, but Give me this, I need to find a match:
a.com
b.com
c.com
aa.com
admin.com
www.com
mail.com
vg.com
As a result, I have found a regular expression to all domains except the admin / www / mail.
I wrote this:
[a-zA-Z0-9]+.com
But how to exclude admin, mail, www
I tried this:
^(www|mail|admin)[a-zA-Z0-9]+.com
But it doesn't work
Try this
\w+(?<!admin|mail|www)\.com
Here it is with some tests
http://www.rubular.com/r/frRl1ucR8J
Further reading on Regular Expressions: http://www.regular-expressions.info/tutorial.html
And the trick I used is called Negative LookBehind http://www.regular-expressions.info/lookaround.html
It is not simple to exclude some things, but here is a link to help:
http://www.codinghorror.com/blog/2005/10/excluding-matches-with-regular-expressions.html
is it possible to use a replace first? You could first do a find/replace to eliminate lines that match the things you want to skip, then use your regular expression.
You would do this to search for a string that doesn't contain admin:
^((?!admin).)*$
I'm not sure how to do it for multiple strings...
I use this, somewhat similar to already answered.
/^[A-Za-z0-9._'%+-]+#(\[(\d{1,3}\.){3}|(?!hotmail|gmail|yahoo|live|msn|outlook|comcast|verizon)(([a-zA-Z\d-]+\.)+))([a-zA-Z]{2,4}|\d{1,3})(\]?)$/i