• Top Members
    Reps
    Posts
  • 834 Replies
    2585 Replies
  • 716 Replies
    2026 Replies
  • 331 Replies
    1928 Replies

Regex match Individual groups

Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
User avatar
AnoPem
VIP - Donator
Posts: 441

Regex match Individual groups

Sat Jan 23, 2016 1:35 am

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
Image

User avatar
Filip
Coding Guru
Posts: 834

Re: Regex match Individual groups

Sat Jan 23, 2016 12:01 pm

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
Posts: 57

Re: Regex match Individual groups

Sun Jan 24, 2016 12:10 am

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

Post Reply

Return to “Coding Help & Support”