Regex pattern to find text either of two URLs [duplicate] - regex

This question already has answers here:
Regular expression to stop at first match
(9 answers)
Closed 2 years ago.
I have the following regex:
(?<=unit/)(.*)(?=/)
I use it to get a page name between unit and the guid.
www.page.com/module/unit/design/6e8c1d2b-34vc-4b5c-71af-8b0f93b01b60?sid=5fh6y172-31d9-4r6b-9a15-daed6c541162&culture=en-US
Now i am receiving an URL like this, with /load before the sid.
www.page.com/module/unit/design/6e8c1d2b-34vc-4b5c-71af-8b0f93b01b60/load?sid=5fh6y172-31d9-4r6b-9a15-daed6c541162&culture=en-US
so i am getting this result from the regex
design/6e8c1d2b-34vc-4b5c-71af-8b0f93b01b60
How can i change the regex in order to get just design, moreover how can i create a regex that find design either or both URLs?

Instead of .* use [^/]* to match any sequence of characters not including /. This will get everything until the next /.
(?<=unit/)[^/]*

Related

Regex Match Pattern with Some Exceptions [duplicate]

This question already has answers here:
Regex: match everything but a specific pattern
(6 answers)
Closed 2 years ago.
I'm trying to find matches for Instagram handles but ignore specific handles.
I'm using
#[A-Za-z0-9\.\_]+
to match any handle starting with an # sign, but I want to ignore handles like #example and #test which for that I have the regex #example|#test.
New to regex and trying to figure out how to do the look ahead and ignore the example and test cases. Not sure how to combine the two into one.
Do this:
#(?!example|test)[A-Za-z0-9._]+
Uses negative lookahead to ignore the handles that are not required.
Demo

Regex Extract on Google Sheets [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
I am trying to find an expression that can be used extract a string after a specific number of characters.
E.g
FR_EN_BR_Student_Exact
FR_EN_NB_Student_Exact
I would want a pattern that can take all characters past the second underscore ( not including the underscore.
Would appreciate any ideas!
I understand basic regex but am having trouble with this specific query.
try:
=ARRAYFORMULA(IFNA(REGEXEXTRACT(A1:A, ".+_.+_(.+_.+_.+)")))

trying to match while excluding from front/behind - Eclipse Negative Lookahead not working as I expect it to [duplicate]

This question already has answers here:
Regular expression for a string containing one word but not another
(5 answers)
Closed 3 years ago.
I am trying to write some regex to use in Eclipse file search that will find "http:", while allowing me to exclude a word or words before and after the "http:"
Before making it work for both in front and behind, I am just trying to get it to work excluding phrases in the front using negative lookahead. So I have been trying this:
^(?!QName).*http:
or
.*^(?!QName).*http:
I would expect this line to not come back in the search:
// QName qn = new QName( "http://BUNDLE.wsdl","bundle");
But it does come back in the search. These both match the line all the way up to http: if QName is not present, or it matches the entire line if QName is present.
Eventually I want to make it more complex where I can exclude words in the front and back:
^(?!QName|xlmns).*http:^(?!word1|word2)
But I am far from that point - however any help on that will be appreciated since I am likely going to have trouble with it too
Credit to Wiktor Stribiżew in the above post
^(?!.*(?:QName|xmlns).*http:).*http:

Find two QnA maker link handler and assign each found regex an html <a> tag [duplicate]

This question already has answers here:
My regex is matching too much. How do I make it stop? [duplicate]
(5 answers)
Closed 3 years ago.
I want a regex for the following string:
For more: [Click here](https://www.google.ca) and [click me](https://www.google.com)
For that My current regex is as follows.
/\[.*\]\((((https?\:\/\/)|(www\.))(\S+))/ig
Give me the regex with that I can find two different links in the same line.
Right now I am finding 1 combined regex for both of them.
My guess is that we have URLs in (), which we can use an expression similar to, if that'd be the case:
\((https?[^\s]+)\)
with a capturing group, where our desired outputs are.
Demo 1
For capturing the [], we would just expand our expression:
(\[.+?])\((https?[^\s]+)\) //$ sign removed
Demo 2

regex matching when not trailing slash [duplicate]

This question already has answers here:
How do I recognize strings that do not end with a slash character ('/') using a regex?
(3 answers)
Closed 4 years ago.
How would a regex look like when i have the input
foo.bar/level/1A
foo.bar/level/1A/test
foo.bar/level/1B
foo.bar/level/1A/blabl/sdffs
foo.bar/test
As a result I only want the urls where the root items in the level folder so
foo.bar/level/1A
and
foo.bar/level/1B
So anything in the level folder that is nog followed by a slash basicly
What is the best regex way to extract these ?
Thx (I realy need to find a good regex training cause I always bump into this stuff when there is look ahead / back and stuff involved)
You can use:
^[^\/]*\/level\/[^\/]*$
Demo: https://regex101.com/r/iqnsjV/1