Count letters directly in IsAlphaNumber instead of matching a regex - #4075
Open
rootkiller6788 wants to merge 3 commits into
Open
rootkiller6788 wants to merge 3 commits into
rootkiller6788 wants to merge 3 commits into
Conversation
IsAlphaNumber() was checking the whole number against the anchored regex
"(?i)(?:.*?[a-z]){3}", which requires the number to end in a letter. That
means vanity numbers ending in a digit (e.g. "800 FLOWER7") were rejected
here while the Java and JavaScript ports, whose pattern has a trailing
".*", accept them. A plain scan for three ASCII letters matches the other
ports and no longer depends on how the regexp engine anchors the match.
Also reject input longer than 250 characters up front, mirroring the
MAX_INPUT_STRING_LENGTH bound that was recently added to the Java port.
Covers numbers like "800 FLOWER7" that have three or more letters but end in a digit, plus over-long input that should be rejected up front. The old code returned false for these even though Java and JavaScript accept them.
mandlil
approved these changes
Sep 9, 2026
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.
Java's isAlphaNumber() was switched to a linear letter-count + a 250-char length bound a while back (PR #4017) because the regex could blow up on long input. The C++ port was left on the old anchored regex "(?i)(?:.*?[a-z]){3}", and that regex is also stricter than the Java/JS one: it requires the number to end with a letter, so "800 FLOWER7" was rejected in C++ but accepted in Java and JavaScript. Since IsAlphaNumber is a public API that should behave the same across ports, I ported the Java approach: count at least three ASCII letters and bail out for anything over 250 chars before running the viable-number regex.
Verified with a small std::regex harness: the old fullmatch is equivalent to (>=3 letters && ends with a letter), the new scan matches the Java/JS semantics, and the existing IsAlphaNumber tests keep passing.