Regex match Individual groups

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
3 posts Page 1 of 1
Contributors
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Regex match Individual groups
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
https://t.me/pump_upp
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: Regex match Individual groups
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
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
SumCode
Dedicated Member
Dedicated Member
Posts: 57
Joined: Fri Aug 03, 2012 2:34 am

Re: Regex match Individual groups
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
3 posts Page 1 of 1
Return to “Coding Help & Support”