Regular expressions that allow only a few characters in a URL

Time:2020-11-20

For example, the restriction allows only the following
a-Z
0-9
Http: / / match coherence
HTTPS: / / match coherence
/It is not allowed to appear two times in succession
&
%
? do not appear two times in succession
=Equal sign
-Middle dash
A kind of Underline
. points are important

There are the following regular coincidence

^((?:http|https)://)?((?![/?]{2,})[a-zA-Z0-9\-._%&=/?])+$

Regexbuddy3 translation tool

^((?:http|https)://)?((?![/?]{2,})[a-zA-Z0-9\-._%&=/?])+$
The assertion is at the beginning of the string
· reverse reference 1
· repeat 0 to 1, matching as much as possible (greedy)
· match with the following regular expressions
■ match with the following regular expression (replace this one with the next one if it fails)
■ matching character “HTTP”
■ match with the following regular expressions (this regular expression fails to match, this set does not match)
■ matching character “HTTPS”
· matching character ‘: / / “
· reverse reference 2
· repeat once to infinity, matching as much as possible (greedy)
Note: you refer back to yourself. The match takes the last reverse reference as the reference. Iterate the repeated reverse references.
· negative look forward
■ match a character “/?” that appears in the list below
■Between 2 and unlimited times, as many times as possible, giving back as needed (greedy)
· matches a character that appears in the list below
■ a character whose range is between a and Z
■ a character whose range is between a and Z
■ a character whose range is 0 to 9
■ character “-“
■ a character is “_ %&=/”One of them
The assertion is at the end of the string