C# Regex | SoloLearn: Learn to code for FREE!


C# Regex

How can I match only letters and spaces? I've come up with [^A-Za-z] but I can't figure out spaces


5/19/2020 12:28:32 AM

Daniel Cooper

4 Answers

New Answer


^[a-zA-Z\s]*$ ^ means start of the string \s means spaces *$ means all what is in brackets till the last element of the string, last element also included


Sebastian Pacurar \s matches any white space character including spaces, tabs, line breaks..


Thanks guys, but I literally forgot about String.Split(), lol. I got it all figured out. Didn't even need to worry about spaces.


([A-Za-z ])+ A-Z matches character from A to Z a-z matches character from a-z matches space character [] matches any character in the set + matches one or more of the preceding token https://regexr.com/54si4