Make the URL only allow regular expressions with some characters

Source: Internet
Author: User

For example, only the following regular expressions are allowed.
A-Z
0-9
Http: // consistent match
Https: // consistent match
/Two consecutive occurrences
&
%
? Two consecutive occurrences
= Equal sign
-Dashes
_ Underline
. Point is very important

There are the following regular expressions

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

RegexBuddy3 translation tool

^ ((? : Http | https )://)? ((?! [/?] {2,}) [a-zA-Z0-9 \-. _ % & =/?]) + $
• Assertions start with a string
• Reverse reference 1
The secondary node repeats 0 to 1 times and matches as many as possible (Greedy)
The condition matches with the following regular expression:
■ Use the following regular expression for matching (this regular expression is replaced by the next regular expression when it fails)
■ Match the character "http"
■ Match with the following regular expression (this regular expression fails to match, and this set does not match)
■ Match the character "https"
The delimiter matches the character ": //".
• Reverse Reference 2
Repeat the repeat once to an infinite number of times and match as many as possible (Greedy)
Note: you can reverse reference itself. The matching will be referenced by the last reverse reference. Repeat reverse reference iteration.
Forward view of negative statements
■ Match the character "/?" in the following list
■ Between 2 and unlimited times, as same times as possible, giving back as needed (greedy)
The delimiter matches a character in the following list.
■ A character in the range of a to z
■ A character in the range of A to Z
■ A character in the range of 0 to 9
■ Character "-"
■ One character is ". _ % & = /?" One of them
• Assertion at the end of the string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.