Regex with includes and excludes (Javascript) [duplicate] - regex

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]+$

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

Replacing a certain number of characters after a match in regular expression [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
I want to find any instance of
\/Network\/Cambric Corporate Center\/
and replace the next 8 characters with nothing.
So something like this
\/Network\/Cambric Corporate Center\/1164.DEV1164
Turns into this
\/Network\/Cambric Corporate Center\/1164
I'm working with a baked in replace regular expression visual programming piece, and this is my first post to here ever so please ask if more info is needed. I basically just need it to look like this
\/Network\/Cambric Corporate Center\/1164
if there is another solution without having to use replace
It is for a frequently updated mass source of data that I need to edit to make more compatible with arrays
Try (\/Network\/Cambric Corporate Center\/).{8} and replace with $1 to keep the first group but not anything else.
Here's the regex with the replacement: https://regex101.com/r/F4Y4VD/1

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, take last match before suffix [duplicate]

This question already has answers here:
Tempered Greedy Token - What is different about placing the dot before the negative lookahead?
(3 answers)
Closed 4 years ago.
I know this is going to sound like the kind of question that's been asked hundreds of times. But I've been searching for over an hour and none of the solution I found worked in my case.
I have many different numbers of the form
\d*'?\d+\.\d\d
An example of string I work with would be
The base item costs 1'245.48, the tax is of 18.45 and the bonus of 250.00, the total price is of 1'013.93. In case of trouble, contact our e-mail. Bank account 784.45
I want to get ONLY the last match corresponding to my regex before e-mail, i.e 1'013.93. I would like to use only regex, no extra python, javascript or anything
I have tried code inspired by this Regex Last occurrence?, this How to capture only last match in Regex, this Find Last Occurrence of Regex Word, and many other expressions of my own, but so far there always seems to be one piece missing
For example, after successfully selecting the very last number with (\d*'?\d+\.\d\d)(?!.*\d*'?\d+\.\d\d), I tried (\d*'?\d+\.\d\d)(?!.*\d*'?\d+\.\d\d)(?=e-mail), which does not match anything.
Any insights?
You could try this:
((\d+')?\d+(\.\d+)?)(?=[^\d]+e-mail)
The first group matches the number you want. From regex101.com:
Something like this with an extra number format check:
((\d{1,3}')*(\d{1,3})\.\d{2})(?=\D+e-mail)
Demo