File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,12 @@ let filtered_ips = commonregex::ip::v4(&log);
30
30
commonregex :: internet :: email (& text )
31
31
```
32
32
33
+ ** URL**
34
+
35
+ ``` rust
36
+ commonregex :: internet :: url (& text )
37
+ ```
38
+
33
39
### IP Addresses
34
40
35
41
** IPv4**
Original file line number Diff line number Diff line change @@ -22,6 +22,28 @@ pub fn email(text: &String) -> Vec<&str> {
22
22
matcher:: match_results ( text, regex_drawer:: internet:: EMAIL )
23
23
}
24
24
25
+ /// Returns matched URLs as a vector of strings
26
+ ///
27
+ /// # Arguments
28
+ ///
29
+ /// * `text` - A String representing the text in which to search.
30
+ ///
31
+ /// # Examples
32
+ ///
33
+ /// ```
34
+ /// extern crate commonregex_rs;
35
+ ///
36
+ /// use commonregex_rs::commonregex;
37
+ ///
38
+ /// let text = String::from("Contribute at https://github.com/fakenine/commonregex-rs !");
39
+ ///
40
+ /// assert_eq!(vec!["https://github.com/fakenine/commonregex-rs"], commonregex::internet::url(&text));
41
+ /// ```
42
+ pub fn url ( text : & String ) -> Vec < & str > {
43
+ matcher:: match_results ( text, regex_drawer:: internet:: URL )
44
+ }
45
+
46
+
25
47
#[ cfg( test) ]
26
48
mod tests {
27
49
use super :: * ;
Original file line number Diff line number Diff line change 1
1
pub mod internet {
2
2
pub const EMAIL : & ' static str = r#"(?i)([A-Za-z0-9!#$%&'*+/=?^_{|.}~-]+@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)"# ;
3
+ pub const URL : & ' static str = r#"(?:(?:https?://)?(?:[a-z0-9.\-]+|www|[a-z0-9.\-])[.](?:[^\s()<>]+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s!()\[\]{};:'".,<>?]))"# ;
3
4
}
4
5
5
6
pub mod ip {
You can’t perform that action at this time.
0 commit comments