Regex to exclude certain strings from path [duplicate] - regex

This question already has answers here:
Regular expression to match a line that doesn't contain a word
(34 answers)
Closed 2 years ago.
I need a regex that will accept all paths except those that have /cantbe or /cantbe/this
So
this/is/ok/filename.tr
is a match but
this/is/ok/cantbe/filename.tr
or
this/is/ok/cantbe/this/filename.tr
are not matches.
I tried
.*(?!\/cant\/)(?!\/cant\/this).*\.tr
but the paths above are still matches

try this
^((?!\/cantbe\b).)*$
Try it out here
This is explained quite well on this question
Regular expression to match a line that doesn't contain a word

Related

Why does the position of my Regex pattern effect the matching? [duplicate]

This question already has answers here:
Why does the order of alternatives matter in regex?
(1 answer)
Order of regular expression operator (..|.. ... ..|..)
(1 answer)
Closed 2 years ago.
Hi I am using a regex checker regex101.com to verify that my regex pattern is working. What I dont understand is why the position of my pattern
\/checkout\/index.jsp\?announceEmpty.*
does not work when it is at the end of my pattern match.
This regex DOES NOT work
\/checkout\/index.jsp.skipReprice=true|\/checkout\/index.jsp|\/checkout\/index.jsp\?announceEmpty.*
vs. this DOES work
\/checkout\/index.jsp.skipReprice=true|\/checkout\/index.jsp\?announceEmpty.*|\/checkout\/index.jsp
and these are the texts to match against
/checkout/index.jsp?skipReprice=true
/checkout/index.jsp
/checkout/index.jsp?announceEmpty=1&lastItemRemoved=Gola%20x%20

negative regex in package.json [duplicate]

This question already has answers here:
Regular expression to match a line that doesn't contain a word
(34 answers)
Closed 3 years ago.
In my package.json, I have a regex to process only the files that contain '.integration.'
The command is the following:
"test:integration": "jest .*\\.integration\\..*"
How can I select files that DON'T contain '.integration.' ?
Maybe, an expression similar to,
^(?!.*\\.integration\\.).*$
might be somewhat close, not sure though.
Demo

How to regex part of a string from and to some certain characters [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
I have the following string and I want to find a proper regex for it, so I can use it in Regular Expression in Jmeter:
DocumentId_123456
The point is that every time the numbers have different length.
so basically I want everything between _ and the end of string.
Please try it, I guess it works in jmeter
DocumentId_(\d+)
Uou can check it here: [https://regex101.com/]

How to forbid symbol in the begin and end of group of letters and numbers [duplicate]

This question already has answers here:
What is the best regular expression to check if a string is a valid URL?
(62 answers)
Closed 5 years ago.
Here is my regex that tries to match a valid URL:
^(https?:\/\/((\b\w[^-][a-zA-Z0-9-]{1,33})\.){1,34}([[a-zA-Z0-9]{1,6})\/?)$
and I've tried to find way to make a simple solution to forbid the use of a hyphen '-' in the beginning and end of a group of letters and numbers.
I'd tried to use \b\w[^-]. But it hasn't helped.
For example, my regex matches this string, but it shouldn't
http://example-.com
I found an answer by myself
^(https?:\/\/([WWW\.]|[www\.])?((([a-zA-Z0-9]|[a-zA-Z0-9][-][a-zA-Z0-9]){1,10})\.){1,33}([[a-zA-Z0-9]{1,6})\/?)$
its just a simple OR [a-zA-Z0-9]|[a-zA-Z0-9][-][a-zA-Z0-9]
If you'll find better solution pls send it :)

Match all Strings without the word "authorize" in them [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Java \ Pattern - how to write a pattern that verifies the lack of a string?
How can I match all strings without the word "authorize" in them via regular expressions? I tried *(authorize){0}* to no avail.
/^(?!.*authorize).*/
This uses a negative lookahead to ensure that the overall pattern will match only if the expression "authorize" cannot match anywhere in the input.