Link to home
Start Free TrialLog in
Avatar of Wayne Barron
Wayne BarronFlag for United States of America

asked on

Grab text from string, ignore text within [brackets]

Hello all;

I am using the following code, to grab the text between (text here) and [text here]
			Dim strWriters as string = "(somebody here) [Something else here]"
			Dim Regex As Regex = New Regex("\(.*?\)")
			Dim Regex1 As Regex = New Regex("\[.*?\]")

			Dim matches As MatchCollection = Regex.Matches(strWriters)
			Dim matches1 As MatchCollection = Regex1.Matches(strWriters)

			Dim count As Integer = matches.Count
			Dim counts As Integer = matches1.Count

			Dim s0 As String = matches(0).Value.ToString
			Dim s1 As String = matches1(0).Value.ToString

Open in new window


The above works great, however. I want to eliminate the use of the Parentheses (text here) altogether.
I still need to grab the text in the brackets, so the brackets have to remain.

Like the code above.
Grab the "somebody here" from the string
And then, another one will grab the Something else here.

Dim strWriters as string = "somebody here [Something else here]"

Open in new window


Assistance on this would be great.
Thanks in advance.
Carrzkiss
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Dim strWriters as string = "somebody here [Something else here]"
Dim Regex As Regex = New Regex("\[.*?\]")

Dim matches As MatchCollection = Regex.Matches(strWriters)
Dim count As Integer = matches.Count
Dim s As String = matches(0).Value.ToString

Open in new window

Avatar of Wayne Barron

ASKER

I do not see how this works.
I did a response.write(s)
And it printed out the full string.
Could you elaborate on how to use this, please?
Never mind my first comment.
I ran it again, and it gets the text in the brackets.
that is not what I asked for.
I asked to ignore the text in the brackets.
ASKER CERTIFIED SOLUTION
Avatar of Wayne Barron
Wayne Barron
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I do not see how this works.
I did a response.write(s)
And it printed out the full string.
Could you elaborate on how to use this, please?
I assumed your initial code worked
Found a solution on my own.