Split & Join List using Regex

I’m attempting to split a list of strings. If a special character exists, remove the special character, if there is a space detected, split the string on the space detected & create a new item within the list. Output list should be distinct values, if possible?

For example:

lis-t should become {list}
check ed should become two list items {‘check’,‘ed’}
With the changes, the final list should be {‘list’,'check, ‘ed’}

I’ve tried lwords.Distint.toList.Select(funciton (x) Regex.Replace(x,“^A-Za-z\S]+”,“”)).toList but the \S seems to be ignored it isn’t giving the required output

Thank you


How about the following?

listStr = listStr.SelectMany(Function(s) System.Text.RegularExpressions.Regex.Replace(s,"[^A-Za-z0-9 ]","").Split({" "c})).ToList

Sample20230419-2aL.zip (2.4 KB)



better to change the vague definition to a set of characters

But could go in this direction

Superb! Exactly what i was looking for & covers all bases. Thanks very much for your help

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.