@@ -30,8 +30,50 @@ Or install it yourself as:
30
30
31
31
## Usage
32
32
33
+ Get the regex:
34
+
35
+ UrlRegex.get(options)
36
+
37
+ where options are:
38
+
39
+ - ` scheme_required ` indicates that schema is required, defaults ` true ` .
40
+
41
+ - ` mode ` can gets either ` :validation ` or ` :parsing ` , defaults ` :validation ` .
42
+
43
+ ` :validation ` asks to return the regex for validation, namely, with ` \A ` prefix, and with ` \z ` postfix.
44
+ That means, it validates whole string:
45
+
46
+ UrlRegex.get(mode: :validation).match('https://www.google.com').nil?
47
+ # => false
48
+ UrlRegex.get(mode: :validation).match('link: https://www.google.com').nil?
49
+ # => true
50
+
51
+ ` :parsing ` asks to return the regex for parsing:
52
+
53
+ str = 'links: google.com https://google.com?t=1'
54
+ str.scan(UrlRegex.get(mode: :parsing))
55
+ # => ["https://google.com?t=1"]
56
+
57
+ # schema is not required
58
+ str.scan(UrlRegex.get(scheme_required: false, mode: :parsing))
59
+ # => ["google.com", "https://google.com?t=1"]
60
+
61
+ ` UrlRegex.get ` returns regular Ruby's [ Regex] ( http://ruby-doc.org/core-2.0.0/Regexp.html ) object,
62
+ so you can use it as usual.
63
+
64
+ All regexes are case-insensitive.
65
+
66
+ FAQ:
67
+
68
+ Q: Hey, I want to parse HTML, but it doesn't work:
69
+
70
+ '<a href =" http://google.com?t=1 " >Link</a >'.scan(UrlRegex.get(mode: : parsing ))
71
+ # => "http://google.com?t=1">Link </a >"
72
+
73
+ A: Well, you probably know that parsing HTML with regex is
74
+ [ a bad idea] ( https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags ) .
75
+
33
76
34
- TODO: Write usage instructions here
35
77
+ parsing html
36
78
+ optimization
37
79
0 commit comments