Results for “Text validation & formatting”
Small, practical examples. Search by task or narrow things down below.
Pad a numeric label to a fixed width
C#: Use a numeric format specifier to add leading zeroes.
C#✓ 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 a quoted string containing spaces
C++: The quoted manipulator extracts a quoted field without splitting at internal spaces.
C++✓ 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
Remove a known suffix safely
Python: Use removesuffix to remove only a matching ending.
Python✓ Tested
Trim surrounding ASCII whitespace
C++: Find the first and last non-whitespace bytes before taking a substring.
C++✓ Tested
Validate a complete identifier
C++: regex_match requires the pattern to match the complete input sequence.
C++✓ 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
Check whether text is valid JSON
Reject malformed input before processing it.
json_valid✓ Tested
Combine text values with a separator
SQL: Use the concatenation operator supported by the selected SQL dialect.
SQL✓ Tested
Combine text values with a separator
SQL Server: Use the concatenation operator supported by the selected SQL dialect.
SQL Server✓ Tested