Skip to content

Improved regex removes unneeded '|' symbol and allows white-space when validating user input for partition value, unit. - #3952

Merged
svartkanin merged 1 commit into
archlinux:masterfrom
okayGravity:master
Nov 29, 2025
Merged

Improved regex removes unneeded '|' symbol and allows white-space when validating user input for partition value, unit.#3952
svartkanin merged 1 commit into
archlinux:masterfrom
okayGravity:master

Conversation

@okayGravity

@okayGravity okayGravity commented Nov 26, 2025

Copy link
Copy Markdown
Contributor

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.

screenshot-2025-11-26_11-52-14

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)

  • Users no longer need to merge value and unit (120GiB) if they used spaced input
  • Accepts flexable white-space
  • Removes literal '|' from unit-matching, improving correctness of regex intent

Regex Explanations

Previous Regex - '([0-9]+)([a-zA-Z|%]*)'

  • (') matches the character ' with index 3910 (2716 or 478) literally (case sensitive)
1st Capturing Group ([0-9]+)
  • Match a single character present in the list below [0-9]
  • (+) matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
  • 0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
2nd Capturing Group ([a-zA-Z|%]*)
  • Match a single character present in the list below [a-zA-Z|%]
  • (*) matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
  • a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
  • A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
  • (|%) matches a single character in the list |% (case sensitive)
  • (') matches the character ' with index 3910 (2716 or 478) literally (case sensitive)
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)

New Regex - '^\s*([0-9]+)\s*([a-zA-Z%])\s$'

  • (') matches the character ' with index 3910 (2716 or 478) literally (case sensitive)
  • (^) asserts position at start of a line
  • \s matches any whitespace character (equivalent to [\r\n\t\f\v ])
  • (*) matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
1st Capturing Group ([0-9]+)
  • Match a single character present in the list below [0-9]
  • (+) matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
  • 0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
  • \s matches any white- space character (equivalent to [\r\n\t\f\v ])
  • (*) matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
2nd Capturing Group ([a-zA-Z%]*)
  • Match a single character present in the list below [a-zA-Z%]
  • (*) matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
  • a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
  • A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
  • % matches the character % with index 3710 (2516 or 458) literally (case sensitive)
  • \s matches any white-space character (equivalent to [\r\n\t\f\v ])
  • (*) matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
  • ($) asserts position at the end of a line
  • (') matches the character ' with index 3910 (2716 or 478) literally (case sensitive)
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

  • Manual check of both spaced and unspaced strings
  • Confirmed no regressions to existing units or number forms
  • ISO test after build

…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 %"
@okayGravity
okayGravity requested a review from Torxed as a code owner November 26, 2025 23:46
@svartkanin
svartkanin merged commit 7732d50 into archlinux:master Nov 29, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants