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.
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
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
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
So I assume you want to get something like this as an output:
KR,
-Filip
Code: Select all
If that's the case you should use:
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`
...
Code: Select all
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./(.*): (.*)/g
KR,
-Filip
CodenStuff wrote:Nope, it's just your sick and dirty mind. You sick twisted warped little pervo
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
Copyright Information
Copyright © Codenstuff.com 2020 - 2023