Improved regex removes unneeded '|' symbol and allows white-space when validating user input for partition value, unit. - #3952
Merged
Conversation
…ion value and unit. - Allows for white space in between groups, aligning better with displayed example. - Removed unneeded | symbol, which was checking as literal rather than working as "or %"
svartkanin
approved these changes
Nov 27, 2025
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.
PR Description:
Small enhancement to size parsing for partition input.
Allows users to enter sizes with or without whitespace between the numeric value and the unit (e.g. 120 GiB). Previously only inputs such as '120GiB' (value,unit) were accepted, while inputs such as '120 GiB' were rejected.
This change improves UX consistency and better aligns with input behavior and displayed examples.
This change is made by updating the regex used for parsing size strings:
-
match = re.match(r'([0-9]+)([a-zA-Z|%]*)', text, re.I)+
match = re.match(r'^\s*([0-9]+)\s*([a-zA-Z%]*)\s*$', text, re.I)Regex Explanations
Previous Regex - '([0-9]+)([a-zA-Z|%]*)'
1st Capturing Group ([0-9]+)
2nd Capturing Group ([a-zA-Z|%]*)
Global pattern flags
New Regex - '^\s*([0-9]+)\s*([a-zA-Z%])\s$'
1st Capturing Group ([0-9]+)
2nd Capturing Group ([a-zA-Z%]*)
Global pattern flags
g modifier: global. All matches (don't return after first match)
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
Tests and Checks