开发者

Modify regex code, only one line

开发者 https://www.devze.com 2023-01-16 08:36 出处:网络
I have this code Dim parts As New List(Of String)(Regex.Split(RichTextBox2.Text, \"~\\d\")) 开发者_JAVA技巧That splits lines in this format into parts:

I have this code

Dim parts As New List(Of String)(Regex.Split(RichTextBox2.Text, "~\d"))

开发者_JAVA技巧That splits lines in this format into parts:

~1Hello~2~3Bye~4~5Morning~6

So if I do MsgBox(parts(5)), it will show me "Morning".


I want to do the exact same thing, but now my line is arranged like this:

Hello, Bye, Morning,


Change "~\d" to ", ?". The question mark after the space means that the space is optional.

Alternatively, assuming that you are only looking for single words, instead of Regex.Split you could use Regex.Matches with the regular expression "\w+".

0

精彩评论

暂无评论...
验证码 换一张
取 消