regex matching when not trailing slash [duplicate] - regex

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

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 pattern to find text either of two URLs [duplicate]

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/)[^/]*

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:

Regex help to filter only 720p [duplicate]

This question already has answers here:
What special characters must be escaped in regular expressions?
(13 answers)
Closed 4 years ago.
I'd like to setup auto download of some Anime using an RSS feed, but only 720p versions. The format never changes and it always looks like below.
[Blahblah] Blahepisode - 12 [720p].mkv
Here is the regex I have come up with but cannot get to work properly.
/.\+[720p]+/g
Any help would be appreciated!
Assuming you have lines that look like your example, it will be mached with the following Regex:
.+(?:\[720p\].mkv)
It maches one or more chacacters at start, followed by '[720p].mkv'.
Note that the Square brackets are escaped to '\[' and '\]', otherwise they have special meaning.
if you only need '[720p]' then you can use:
\[720p\]

Sublime text regex - remove text in parenthesizes [duplicate]

This question already has answers here:
My regex is matching too much. How do I make it stop? [duplicate]
(5 answers)
How can I remove text within parentheses with a regex?
(9 answers)
Closed 4 years ago.
I am having list on telephone numbers in my js file, and some of them have in parenthesizes translations that I don't need:
Azerbaijan (Azərbaycan)
I wont to find regex in sublime to do that, but I cannot find the right command. I have tried:
((.))
((*))
\(.*)\
\(.*\)
But I aways remove something different ... If someone know the solution, please help.
Ok as Paul Bak said the (.*) works at his computer, and it does work, just that my js file is compressed all in same line so it removes everything after the (...
I beautified js and use this regex and now it is solved.