RegExpValidator does not validate a URL pattern correctly

前端 未结 3 2024
再見小時候
再見小時候 2021-01-26 04:58

The URL http://www.ftd.de/rss2 is not valid when I check it against the below RegEx in this (unadventurous) :



        
3条回答
  •  情话喂你
    2021-01-26 05:31

    The sequence \uhhhh doesn't seem to be recognized in the 2 online Flex-based testers. This is either a bug in the implementation of Flex regular expression, or possibly a bug in the implementation of the tester, or possibly a mistake in the documentation.

    Please check whether the original regex works in your program before using the regex below.

    This is a work-around for testing the regex on the online testers: replace all \uhhhh with \x{hhhh}. I am not sure whether it still works in the actual code. This is not documented anywhere, and I just found this out from an answer by other user.

    ^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$
    

    Demo on RegExr (I used the test data from the link in the question)

提交回复
热议问题