Results for “Text validation & parsing”
Small, practical examples. Search by task or narrow things down below.
Remove a known suffix safely
Python: Use removesuffix to remove only a matching ending.
Python✓ Tested
Remove a trailing carriage return from a line
Bash Scripts: Use an ANSI-C quoted carriage return as the suffix pattern.
Bash Scripts✓ Tested
Set and clear a bit in a shell integer
Bash Scripts: Use shifts and bitwise operators for a small flag field.
Bash Scripts✓ Tested
Split a record while retaining its remainder
Bash Scripts: The final read variable receives the remainder of a delimited record.
Bash Scripts✓ Tested
Test numeric divisibility with a remainder
Bash Scripts: The modulo operator computes an integer remainder.
Bash Scripts✓ Tested
Validate a complete identifier
Java: String.matches requires the regular expression to match the entire input.
Java✓ Tested
Validate a complete identifier with a regex
C#: Use absolute anchors and a timeout so the regex checks the complete input with a bounded execution time.
C#✓ Tested
Validate an entire identifier
Python: Use fullmatch so a regex must consume the complete input.
Python✓ Tested
Convert between hexadecimal text and bytes
PowerShell: Use the .NET hexadecimal helpers instead of parsing byte pairs manually.
PowerShell✓ Tested
Limit typed text to a maximum length
HTML: Maxlength limits ordinary user editing without replacing server-side validation.
HTML✓ Tested
Parse an integer with validation
Validate range and trailing characters when parsing a C integer with strtol.
C✓ Tested
Require a nonempty text value
HTML: The required attribute makes an empty text control fail native constraint validation.
HTML✓ Tested