Skip to content

Commit 85c1319

Browse files
committed
description
1 parent 56c5aaa commit 85c1319

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,50 @@ Or install it yourself as:
3030

3131
## Usage
3232

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+
3376

34-
TODO: Write usage instructions here
3577
+ parsing html
3678
+ optimization
3779

0 commit comments

Comments
 (0)