Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5677827
commit fd84a46
Showing
6 changed files
with
67 additions
and
36 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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import "regexp" | ||
|
||
func findNamedRegexMatch(pattern, text string) map[string]string { | ||
re := regexp.MustCompile(pattern) | ||
match := re.FindStringSubmatch(text) | ||
result := make(map[string]string) | ||
if len(match) == 0 { | ||
return result | ||
} | ||
for i, name := range re.SubexpNames() { | ||
if i == 0 { | ||
continue | ||
} | ||
result[name] = match[i] | ||
} | ||
return result | ||
} | ||
|
||
func findAllNamedRegexMatch(pattern, text string) []map[string]string { | ||
re := regexp.MustCompile(pattern) | ||
match := re.FindAllStringSubmatch(text, -1) | ||
var results []map[string]string | ||
if len(match) == 0 { | ||
return results | ||
} | ||
for _, set := range match { | ||
result := make(map[string]string) | ||
for i, name := range re.SubexpNames() { | ||
if i == 0 { | ||
result["text"] = set[i] | ||
continue | ||
} | ||
result[name] = set[i] | ||
} | ||
results = append(results, result) | ||
} | ||
return results | ||
} | ||
|
||
func replaceAllString(pattern, text, replaceText string) string { | ||
re := regexp.MustCompile(pattern) | ||
return re.ReplaceAllString(text, replaceText) | ||
} |
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
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
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
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