Repository navigation
fix(js/ts/python/beam): make a failed Regex.Match behave like Match.Empty - #5321
Merged
Merged
Conversation
Contributor
Python Type Checking Results (Pyright)
Excluded files with errors (4 files)These files have known type errors and are excluded from CI. Remove from
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On .NET, a failed
Regex.MatchreturnsMatch.Empty, an object with one failed group. Before this change, a failed match wasnullon JS/TS,Noneon Python, and a map withindex => -1on Beam.In the table,
misRegex("(a)(?<name>b)").Match("xyz")andokisRegex("(a)(b)?").Match("xa"). "ok" means that the target already gave the .NET value.isNull mfalsetruetruem.ToString()"""null""None"m.Index0AttributeError-1m.Value""TypeErrorm.Groups.Count103m.Groups.[1].SuccessfalseIndexErrorm.Groups.["name"].SuccessfalsebadarithisNull (m.NextMatch())falsetruetrueok.ToString()"a""a,a,""<re.Match object ...>"ok.Groups.[2].Length0TypeErrorok.Groups.[2].Index0-1ok.Groups.[5].SuccessfalseIndexErrorfunction_clauseWith this change, each cell gives the .NET value. The compile errors do not change.
Warning
On JS/TS and Python, a failed match is not
nullnow. Code such asisNull morOption.ofObj mnow uses the non-null branch, as on .NET. To find a failed match, usem.Success.Changes:
Matchused as aGroup(:> Group,Seq.cast<Group>) now gives the correctSuccess,ValueandLength.EMPTY_MATCHand new library functions. The existing functions do not change. AGroupstored in a variable reads about 1.1 times slower than on main. Directm.Groups.[i]reads are faster.Not fixed:
Match.NextMatchdoes not compile, andGroups.Countthrowsfunction_clausefor a pattern with a lookbehind(?<=.Group.Indexdoes not compile.$"{m}",%Aand a genericstring xof a successful match do not give"a". Main has the same problem.ToString()of a failed match andGroups.[5]do not give the .NET value.NextMatchand theGroupupcast do not compile.isNull m,m.ToString()andNextMatchdo not compile.