Shaun
Shaun

Reputation: 13

REGEX to extract data from slightly different strings in VB.NET

I've got the following three strings that I need to extract some data from

randomData1§randomData2§randomData3
randomData1§randomData2§randomData3
randomData§randomData§randomData1§randomData2§randomData3

I need an expression that would work with all three of the above strings to give:

(randomData1) (randomData2) (randomData3)
(randomData1) (randomData2) (randomData3)
(randomData§randomData§randomData1) (randomData2) (randomData3)

randomData2 and randomData3 will always be numbers (ex: 10, 100, 1045, etc) and always be separated by §. Anything towards the left of §randomData2§ can hugely vary might also contain the delimiter §.

Any help would be appreciated.

Upvotes: 1

Views: 146

Answers (1)

arkascha
arkascha

Reputation: 42885

You can 'anchor' a regex matching pattern to the end of the subject string using the '$' char as a last char of the pattern. So try something like this:

^(.+)§([^§]+)§([^§]+)$

Note that I have no idea about VB, this is plain regex usage. I assume VB uses some standard regex engine.

Upvotes: 1

Related Questions