Requirement: {code...} URL sample: {code...} Of course, simple URLs are also required to be matched to solve Regular Expressions:
When the client uploads a string, all URLs must be matched from the string, including parameters (including ports) after the domain name or IP address)
URL example:
Http: // 127.0.0.1/metinfo/img. php? Class1 = 1 & serch_ SQL = % 201 = if % 28 ascii % 28 substr % 28 user % 28% 29,1, 1% 29% 29 = 114,1, 2% 29% 23 or http://www.baidu.com/metinfo/img/img.php? Class1 = 1 & serch_ SQL = % 201 = if % 28 ascii % 28 substr % 28 user % 28% 1% 29%, 2% 29% 29 = 114,1, 23
Of course, simple URLs must also be matched.
Solving Regular Expressions
Reply content:
Requirements:
When the client uploads a string, all URLs must be matched from the string, including parameters (including ports) after the domain name or IP address)
URL example:
Http: // 127.0.0.1/metinfo/img. php? Class1 = 1 & serch_ SQL = % 201 = if % 28 ascii % 28 substr % 28 user % 28% 29,1, 1% 29% 29 = 114,1, 2% 29% 23 or http://www.baidu.com/metinfo/img/img.php? Class1 = 1 & serch_ SQL = % 201 = if % 28 ascii % 28 substr % 28 user % 28% 1% 29%, 2% 29% 29 = 114,1, 23
Of course, simple URLs must also be matched.
Solving Regular Expressions
Use a broad regular expression to match all URLs. For example
https?:\/\/\S+
Then useparse_urlFunction
^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*$http://regexlib.com/Search.aspx?k=url&c=-1&m=5&ps=20
This is probably the case in Java.
String str = "received String" String regex = "(http: | https :) // [^ [A-Za-z0-9 ,:\\._\\? % & + \-=/#] * "; Pattern pattern = Pattern. compile (regex); Matcher matcher = pattern. matcher (str); while (matcher. find () {String url = matcher. group (); System. out. println (url );}
The following string is tested.
String str = "http: // 127.0.0.1: 6666/" + "https://www.baidu.com/" + "http: // 127.0.0.1/metinfo/img. php? Class1 = 1 & serch_ SQL = % 201 = if % 28 ascii % 28 substr % 28 user % 28% 1% 29%, 29 =, 2% 29% 23 \ n "+" or \ n "+" Haha http://www.baidu.com: 85676/metinfo/img. php? Class1 = 1 & serch_ SQL = % 201 = if % 28 ascii % 28 substr % 28 user % 28% 1% 29%, 2% 29% 29 = 114,1, 6666 23 are correct ";
Output
http://127.0.0.1:6666/https://www.baidu.com/http://127.0.0.1/metinfo/img/img.php?class1=1&serch_sql=%201=if%28ascii%28substr%28user%28%29,1,1%29%29=114,1,2%29%23http://www.baidu.com:85676/metinfo/img/img.php?class1=1&serch_sql=%201=if%28ascii%28substr%28user%28%29,1,1%29%29=114,1,2%29%23
What are you asking about PHP? Sorry, I don't know PHP...
The regular expression is the same. Move your head.