-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multiple bug fixes and enhancements for std regex (#256)
Implement namedGroups (which was missing from the first implementation) - JS is tricky because you need to convert Python-style named groups (the only ones supported by RE2) to perl ones - You need to manually find them due to the lack of clear API in the JDK Align our implementation with jrsonnet implementations: - return null if no match - make fullmatch just partialmatch with anchors - it also allows us to share more code. Fix the - problem with regexQuote in RE2 across the board
- Loading branch information
1 parent
7d75fd7
commit 9143c58
Showing
8 changed files
with
150 additions
and
113 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
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
std.assertEqual(std.native('regexFullMatch')(@'e', 'hello'), null) && | ||
|
||
std.assertEqual( | ||
std.native('regexFullMatch')(@'h.*o', 'hello'), | ||
{ | ||
string: 'hello', | ||
captures: [], | ||
namedCaptures: {}, | ||
} | ||
) && | ||
|
||
std.assertEqual( | ||
std.native('regexFullMatch')(@'h(.*)o', 'hello'), | ||
{ | ||
string: 'hello', | ||
captures: ['ell'], | ||
namedCaptures: {}, | ||
} | ||
) && | ||
|
||
std.assertEqual( | ||
std.native('regexFullMatch')(@'h(?P<mid>.*)o', 'hello'), | ||
{ | ||
string: 'hello', | ||
captures: ['ell'], | ||
namedCaptures: { | ||
mid: 'ell', | ||
}, | ||
} | ||
) && | ||
|
||
std.assertEqual(std.native('regexPartialMatch')(@'world', 'hello'), null) && | ||
|
||
std.assertEqual( | ||
std.native('regexPartialMatch')(@'e', 'hello'), | ||
{ | ||
string: 'hello', | ||
captures: [], | ||
namedCaptures: {}, | ||
} | ||
) && | ||
|
||
std.assertEqual( | ||
std.native('regexPartialMatch')(@'e(.*)o', 'hello'), | ||
{ | ||
string: 'hello', | ||
captures: ['ll'], | ||
namedCaptures: {}, | ||
} | ||
) && | ||
|
||
std.assertEqual( | ||
std.native('regexPartialMatch')(@'e(?P<mid>.*)o', 'hello'), | ||
{ | ||
string: 'hello', | ||
captures: ['ll'], | ||
namedCaptures: { | ||
mid: 'll', | ||
}, | ||
} | ||
) && | ||
|
||
std.assertEqual(std.native('regexQuoteMeta')(@'1.5-2.0?'), '1\\.5\\-2\\.0\\?') && | ||
|
||
|
||
std.assertEqual(std.native('regexReplace')('wishyfishyisishy', @'ish', 'and'), 'wandyfishyisishy') && | ||
std.assertEqual(std.native('regexReplace')('yabba dabba doo', @'b+', 'd'), 'yada dabba doo') && | ||
|
||
std.assertEqual(std.native('regexGlobalReplace')('wishyfishyisishy', @'ish', 'and'), 'wandyfandyisandy') && | ||
std.assertEqual(std.native('regexGlobalReplace')('yabba dabba doo', @'b+', 'd'), 'yada dada doo') && | ||
|
||
true |
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 was deleted.
Oops, something went wrong.