-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support detecting which relaxed matches are lone emails
This doesn't require new API nor does it require us to do a second regular expression match on each string, so I think it's the right way. We can also add more subexpression names later which might be useful, such as "web URL without scheme" or "URL scheme". Updates #53.
- Loading branch information
Showing
2 changed files
with
20 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,18 @@ func ExampleStrictMatchingScheme() { | |
// Output: | ||
// [https://foo.com/dl] | ||
} | ||
|
||
func Example_filterEmails() { | ||
s := "Email [email protected] about any issues with foo.com or https://foo.com/dl" | ||
rx := xurls.Relaxed() | ||
idxEmail := rx.SubexpIndex("relaxedEmail") | ||
for _, match := range rx.FindAllStringSubmatch(s, -1) { | ||
if match[idxEmail] != "" { | ||
continue // skip lone email addresses | ||
} | ||
fmt.Println(match[0]) | ||
} | ||
// Output: | ||
// foo.com | ||
// https://foo.com/dl | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters