Page 1 of 1

Regex match Individual groups

Posted: Sat Jan 23, 2016 12:35 am
by AnoPem
Hello im having a problem with regex, again ...

I named the values i get from the regex, i can see i get the values but my problem is that i cant figure out how i organize it proberly. I want to take the value from group name title into my string called title and my tags into an string array but im lost in how i can achieve this? any sugguestions is much apreciated

This is what i get from my regex
Group_name: value
Code: Select all
Title: This is the title
main: main1
tags: 222
tags: 285
tags: 409
images: sample_images
images: sample_images
images: sample_images
description: This is the description

Re: Regex match Individual groups

Posted: Sat Jan 23, 2016 11:01 am
by Filip
So I assume you want to get something like this as an output:
Code: Select all
MATCH 1
1.	[0-5]	`Title`
2.	[7-24]	`This is the title`
MATCH 2
1.	[25-29]	`main`
2.	[31-36]	`main1`
MATCH 3
1.	[37-41]	`tags`
2.	[43-46]	`222`
MATCH 4
1.	[47-51]	`tags`
2.	[53-56]	`285`
...
If that's the case you should use:
Code: Select all
/(.*): (.*)/g
Please note, I quit VB years ago and this is PHP based regex. I don't recall how regex works in VB.net, but you get the context.

KR,
-Filip

Re: Regex match Individual groups

Posted: Sat Jan 23, 2016 11:10 pm
by SumCode
So if I understand what you're looking for you want to get 'title' and put it in a variable named 'title' and put 'tags' under a variable named 'tags'.
Code: Select all
Dim Title = Regex.Match(text, "Title:\s*(.*)").Groups(1).Value
Dim Tags = Regex.Matches(text, "tags:\s*(.+)").Cast(Of Match)().Select(Function(x) x.Groups(1).Value) 'Where text would be whatever string you are getting