-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(re): add compile function to regex package
also, fix re.Split functions to work with infinite matches. This brings lots of general work on the re package, including basic tests.
- Loading branch information
Showing
3 changed files
with
249 additions
and
32 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
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 |
---|---|---|
@@ -1,18 +1,20 @@ | ||
load("re.star", "re") | ||
load("assert.star", "assert") | ||
|
||
pattern = "(\w*)\s*(ADD|REM|DEL|EXT|TRF)\s*(.*)\s*(NAT|INT)\s*(.*)\s*(\(\w{2}\))\s*(.*)" | ||
test = "EDM ADD FROM INJURED NAT Jordan BEAULIEU (DB) Western University" | ||
match_pattern = "(\w*)\s*(ADD|REM|DEL|EXT|TRF)\s*(.*)\s*(NAT|INT)\s*(.*)\s*(\(\w{2}\))\s*(.*)" | ||
match_test = "EDM ADD FROM INJURED NAT Jordan BEAULIEU (DB) Western University" | ||
match_r = re.compile(match_pattern) | ||
|
||
assert.eq(re.match(pattern,test), [(test, "EDM", "ADD", "FROM INJURED ", "NAT", "Jordan BEAULIEU ", "(DB)", "Western University")]) | ||
assert.eq(re.sub(pattern, "", test), "") | ||
assert.eq(re.match(match_pattern,match_test), [(match_test, "EDM", "ADD", "FROM INJURED ", "NAT", "Jordan BEAULIEU ", "(DB)", "Western University")]) | ||
assert.eq(match_r.match(match_test), [(match_test, "EDM", "ADD", "FROM INJURED ", "NAT", "Jordan BEAULIEU ", "(DB)", "Western University")]) | ||
|
||
# assert.eq() | ||
# re.fullmatch("foo") | ||
# re.split("foo") | ||
# re.findall("foo") | ||
# re.finditer("foo") | ||
# re.sub("foo") | ||
# re.subn("foo") | ||
# re.escape("foo") | ||
# re.purge("foo") | ||
assert.eq(re.sub(match_pattern, "", match_test), "") | ||
assert.eq(match_r.sub("", match_test), "") | ||
|
||
space_r = re.compile(" ") | ||
assert.eq(re.split(" ", "foo bar baz bat"), ("foo", "bar", "baz", "bat")) | ||
assert.eq(space_r.split("foo bar baz bat"), ("foo", "bar", "baz", "bat")) | ||
|
||
foo_r = re.compile("foo") | ||
assert.eq(re.findall("foo", "foo bar baz"), ("foo",)) | ||
assert.eq(foo_r.findall("foo bar baz"), ("foo",)) |