Regex Match Pattern with Some Exceptions [duplicate] - regex

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

Related

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:

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

Regex with includes and excludes (Javascript) [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 4 years ago.
I have been tasked with checking for certain patterns in an email subject and not allowing a user to send the email based on those patterns. Problem is... I have to use an existing regex. The existing regex uses matching patterns to allow the user to send. In my case, I want to check for a pattern to not allow. I have googled, and attempted a million different ways of doing this. Can't get it all to work.
So here is what I have to check for:
FW:
FWD:
RE:
FW:
RE;
FW-
RE-
FW,
RE,
So here is the exisiting pattern that I need to search for ANYWHERE not just beginning:
^[\w\d\s\+\-\/\\~!##$%&*()_.,'?\u2600\u2715\u2716\u2713\u2714\u2606\u260E\u00A9\u00A3\u2612\u2614\u2615\u2618\u2619\u261A\u261B\u261C\u261D\u261E\u261F\u00AE\u00A2\u00BC\u00BD\u00BE\u2122\u263D\u263E\u2668\u2672\u2661\u2662\u2663\u2664\u2665\u2666\u2669\u266A\u266B\u266C\u2672\u267B\u267E\u267F\u2692\u2693\u2694\u2698\u269C\u26A0]+$
You just have to add a negative lookahead to your pattern:
(?!.*?\b(?:FWD?|RE)[-:;,])
The .*? will enforce the condition anywhere in the pattern.
So the pattern ends up like this:
^(?!.*?(?:FWD?|RE)[-:;,])[\w\d\s\+\-\/\\~!##$%&*()_.,'?\u2600\u2715\u2716\u2713\u2714\u2606\u260E\u00A9\u00A3\u2612\u2614\u2615\u2618\u2619\u261A\u261B\u261C\u261D\u261E\u261F\u00AE\u00A2\u00BC\u00BD\u00BE\u2122\u263D\u263E\u2668\u2672\u2661\u2662\u2663\u2664\u2665\u2666\u2669\u266A\u266B\u266C\u2672\u267B\u267E\u267F\u2692\u2693\u2694\u2698\u269C\u26A0]+$