Regular Expressions Matching Simple Patterns Matching leading/trailing whitespace

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Trailing spaces

\s*$: This will match any (*) whitespace (\s) at the end ($) of the text

Leading spaces

^\s*: This will match any (*) whitespace (\s) at the beginning (^) of the text

Remarks

\s is a common metacharacter for several RegExp engines, and is meant to capture whitespace characters (spaces, newlines and tabs for example). Note: it probably won't capture all the unicode space characters. Check your engines documentation to be sure about this.



Got any Regular Expressions Question?