Reputation: 746
I want to have a string in the following format
"FAG001 FAG002 FAG003"
and want to split it into
"FAG001" "FAG002" "FAG003"
using a regular expression. Unfortunately my knowledge of regular expression synatax is limited to say teh least. I have tried things like
Dim result = Regex.Split(npcCodes, "([A-Z]3[0-9]3)").ToList
without luck
Upvotes: 1
Views: 838
Reputation: 49990
No need of regex here, you could use String.Split
Dim result As String() = npcCodes.Split(new Char[]{" "})
But if you really want to use regex :
Dim result = Regex.Split(npcCodes, " ").ToList()
Upvotes: 4
Reputation: 700720
The regular expression to use in the Split
method would be really simple:
Dim result = Regex.Split(npcCodes, " ").ToList
As the expression only matches a single character, you can just as well use the regular Split
method in the String
class:
Dim result = npcCodes.Split(" "C).ToList
Upvotes: 0
Reputation: 839044
As madgnome has pointed out you don't need regular expressions here if the string is always separated with spaces.
However for your information the error you made was that you need curly braces for numeric quantifiers:
[A-Z]{3}
And instead of Regex.Split you can uses Regex.Matches
.
Upvotes: 2