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
LVL 31
Wayne BarronAuthor, Web DeveloperAsked:
Who is Participating?
 
Wayne BarronAuthor, Web DeveloperAuthor Commented:
I found something that works.

Dim leftString = sampleInput.Substring(0, sampleInput.IndexOf("["))
Response.Write(leftString)

Open in new window


I am set, this is what I needed.
0
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
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

0
 
Wayne BarronAuthor, Web DeveloperAuthor Commented:
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?
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
Wayne BarronAuthor, Web DeveloperAuthor Commented:
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.
0
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
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
0
 
Wayne BarronAuthor, Web DeveloperAuthor Commented:
Found a solution on my own.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.