Looking for a Regex only match uppercases and ignore web link - regex

i'm looking for a Regex only matching a certain number of uppercases and ignore uppercases in web link.
Here is an example i'm looking for :
ABCDEFG : Matching
abcDEFG : Matching
https://stackoverflow.com/ABCDEFG : not matching
I try this and it's work perfectly for the 2 examples but matching the web link too :
[A-Z][A-Z\d]{5,}

You could use a negative lookahead in front of the pattern to exclude URLs:
^(?!https?://).*[A-Z]{3,}.*$
The above would match any input having three or more continuous capital letters, and so would match:
ABCDEFG
abcdEFG

Related

Regular expression selectively match

Suppose there are the following strings:
https://domain1.com
https://domain2.com
https://domain3.com
https://testdomain.com
https://domain4.com
https://domain5.com
random text
293928382
How can I match only strings that have http but also exclude ones that contain testdomain for example? Currently I have this which excludes testdomain
^((?!testdomain).)*$
However I don't know how to combine the http matching part with the above expression. Can someone please help me combine the above with matching http as well?
The objective is to match:
https://domain1.com
https://domain2.com
https://domain3.com
https://domain4.com
https://domain5.com
Thanks!
You may use this regex with a negative lookaheadd:
^https?://(?!(?:www\.)?testdomain\.).+$
RegEx Demo
RegEx Details:
^https?://: Match http:// or https:// at the start
(?!(?:www\.)?testdomain\.): Negative lookahead to assert that we don't have www.testdomain.com or testdomain.com right after
.+$: Match 1+ of any character

Pull last 3 charecters from Regex positive lookhead match

I have the following regex expression ^.*?(?=\.) and i'm looking to modify it so that i can pull the 3 charecter country code (bold) from a given path. Right now the regex just creates a group before the period.
/path/to/folder/Conclusions_Pakistan_2019-09-13_PAK.pdf
regex101 link: https://regex101.com/r/FGjqSl/1
Your regex ^.*?(?=\.) matches everything from start until it asserts presence of . hence it matches too much.
You may just use this regex 3 character country code comprising all upper case letters:
[A-Z]{3}(?=\.)
Updated Regex Demo

Match URL Paths A+ or B+ but not AX+

I am not good in Regex and need to get an answer on the following problem.
I am trying to match/not match URL Paths
I need to match
/appA or
/appB
But do NOT Match
/appA/download
This is used within an Apache proxy to identify urls for which to set authentication rules.
(^\/(appA|appB))
works almost but includes /appA from /appA/Download
I cannot use (^\/(appA|appB)$) as that would eliminate all other URLS starting with /appA or /appB.
What I am looking for is a regex which matches the /appA or /appB in
/appA
/appA/something
/appB
/appB/something
Does not match /appA when /download follows.
/appA/download
/appA/downloadsomething
Try the following pattern:
^\/(app[AB])(?!\/download).*
It uses a negative lookahead to check against download.
You can see it demo'd at https://regexr.com/4mqah.
I believe what you need is a negative look ahead. In regex: (?!<pattern>)
Your regex should be able to match the full string using this method (using ^ and $) like so:
(^\/(appA|appB))(?!\/download).*$
The Negative look ahead: (?!\/download) will exclude matches where "/download" follows right after /appA or /appB
Note: The .* is going to match the rest of the string (ex: /something in /appA/something) but is optional so /appA still is a valid match.
Here is a RegexR to show the examples: RegexR - (^/(appA|appB))(?!/download).*$

regex expression contains a word and does not contain another

I am trying to write a regex expression that would be give the line that does not contain google but contains com
For Example:
www.google.com
www.msn.com
www.msn
it should match www.msn.com because it contains com and doesn't contain google.
Is this possible?
You can use a negative lookahead regex for your requirement:
^(?!.*google).*\.com
RegEx Demo
RegEx Breakup:
^: Start
(?!.*google): Negative lookahead to assert we don't have google ahead
.*\.com: Match .com after 0 or more characters

Regex to match N-NN-NN

I need some help with a RegEx pattern match.
How do i write a regex if i want it to match
N-NN-N-NN-NN-N-NNN
but also
N-NN-NN-NN
Exmaple:
10pcs- ratchet spanner combination wrench 6-8-10-11-12-13-14-15-17-19
Cr-v,heated 12pcs-1/4dr 4-4.5-5-5.5-6-7-8-9-10-11-12-13 Cr-v,heated
17pcs-1/2dr 10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-27-30
Cr-v,heated 1-2-33 Cr-V heater 1-.2-1-4
It needs to match where they is at least 2 - in the total string. So a phone number like this 020-11223344 is not to be matched.
The strings almost always look like this 6-8-10-11-12-13-14-15-17-19 , except sometimes a . can apper before a number, they also differ in length, is it possible?
I came up with this so far but it also matches on phone numbers and when a . appears it doenst match at all.
(\d-[^>])
On this page you can find the different patters: http://www.cazoom.nl/en/partij-aanbod/186-pcs-working-tools-trolly-3
What about this pattern:
[\d.]+(?:-[\d.]+){2,}
Match [\d.]+ if followed by at least 2x -[\d.]+
(?: Using a non capturing group for repetition.
test at regex101
The following regex will match the thing.
(?:\.?\d\.?\d?-){2,}\.?\d\.?\d?
Debuggex Demo
Just try with following regex:
^\d-\d{2}-\d(\d-\d{2})|(\d-\d{2}-\d-\d{3})$