Results for “Text validation & parsing”
Small, practical examples. Search by task or narrow things down below.
Extract named regex fields
Python: Use named capture groups to parse a known date-shaped identifier.
Python✓ Tested
Extract successive regex matches
Java: Use a Matcher loop to find all unsigned integer tokens in Java text.
Java✓ Tested
Format a numeric label with leading zeroes
Bash Scripts: Use a constant printf format string and supply values as separate arguments.
Bash Scripts✓ Tested
Increment a counter without an unexpected errexit
Bash Scripts: An assignment avoids the zero-result exit status of a standalone arithmetic post-increment.
Bash Scripts✓ Tested
Normalize canonically equivalent Unicode strings
C#: Normalize to NFC before an ordinal comparison of equivalent character sequences.
C#✓ Tested
Normalize equivalent Unicode strings
Python: Normalize to NFC before comparing canonically equivalent text.
Python✓ Tested
Pad a numeric label to a fixed width
C#: Use a numeric format specifier to add leading zeroes.
C#✓ Tested
Parse digits with leading zeroes as decimal
Bash Scripts: The 10# prefix avoids Bash treating a leading zero as an octal notation.
Bash Scripts✓ Tested
Process the lines of an in-memory string
Java: Use String.lines to handle common line terminators without retaining them.
Java✓ Tested
Quote a literal search term for a regex
C#: Regex.Escape prevents metacharacters in a literal term from changing the pattern.
C#✓ Tested
Read fields captured by a Bash regular expression
Bash Scripts: BASH_REMATCH contains the full match followed by capture groups after a successful regex test.
Bash Scripts✓ Tested
Remove a known prefix safely
Python: Use removeprefix instead of lstrip when removing a literal prefix rather than a set of characters.
Python✓ Tested