Extracting strings using regex

Anyone know the regex squence to return just [a-z] and [A-Z] and a space, but nothing else from a string?
Eg

Test 1234 test!@£$%^&*(

to return
Test test

A RegEx will return whatever matches the pattern. so you could extract the string in parts by putting this pattern in a loop: [a-z ]+ (note the space within the brackets), then concatenate the parts yourself. Or you could replace every unwanted character in the string with nothing.

dim rx as new RegEx
rx.SearchPattern = "[^a-z ]+"
rx.ReplacementPattern = ""
rx.Options.ReplaceAllMatches = true
dim r as string = rx.Replace( sourceText )

You could get even fancier and avoid the doubled-up spaces by only including spaces where there is an a-z following:

dim rx as new RegEx
rx.SearchPattern = "(?!\\x20?[a-z])."
rx.ReplacementPattern = ""
rx.Options.ReplaceAllMatches = true
dim r as string = rx.Replace( sourceText )

I don’t so post your code.

This works here, including spaces, so perhaps post some sample text, and what you expect to get back vs. what you are actually getting back.

At that point, I’d change the pattern like this:

rx.SearchPattern = "[^a-z\\t\\x20]"

That will remove anything that is not a letter, tab, or space. This may leave you with doubled-up tabs or spaces and you can deal with that (if needed) with other patterns. For example, to squeeze all spaces:

rx.SearchPattern = "\\x20{2,}"
rx.ReplacementPattern = " " // That's a single space

Or you can remove any space that is followed by a whitespace character:

rx.SearchPattern = "\\x20(?=\\s)"
rx.ReplacementPattern = ""