John
John

Reputation: 7880

Simple regex match string

I have a simple string : s:10:"char1";s:2:"13";i:1;a:8:, i'd like to match that 13 from inside " ", in PHP i would do something like : /s:\d\d?:\"char1\";s:\d\d?:\"(.*?)\";i:\d\d?;a:\d\d?:/i but i'm not good in vb's match methods,so please give me full example how i can match what i need ( it is possible to be multiple matches (2) ). Thanks

Upvotes: 1

Views: 782

Answers (1)

Marcello Faga
Marcello Faga

Reputation: 1204

the regex pattern to put in a Regex .Net object should be :

s\:\d+\:"(\d+)"

in order to identify any pattern s:x:"y" (x and y intended as numeric values) can contain the number y, in your case 13...

It matches all the occurences.

Then passing at the VB level, i'm not so good, i give you a code draft (to verify):

Dim pattern As String = "s\:\d+\:""(\d+)"""

Dim input as String = .......

For Each match As Match In Regex.Matches(input, pattern, RegexOptions.IgnoreCase)
         Console.WriteLine("{0} - {1}", _
                           match.Value, match.Groups(1).Value)

match.Groups(1) gives you the number 13 (\d+).

match.Value gives you the whole match value s\:\d+\:"(\d+)".

Upvotes: 1

Related Questions