Solved

What is the correct way to use Regex for this probelm?

Posted on 2008-10-08
3
212 Views
Last Modified: 2013-12-17
I have a string that is built something like this.

Dim strTest As New System.Text.StringBuilder

        For I = 1 To 100
            strTest.Append(Chr(128))
            strTest.Append(I.ToString)
            strTest.Append(Chr(129))
        Next

        Dim regPart As New System.Text.RegularExpressions.Regex(Chr(128) + ".*" + Chr(129))
        For Each matchPart As System.Text.RegularExpressions.Match In regPart.Matches(strTest.ToString)
            Dim strTest2 As String = matchPart.ToString
        Next

What I want the regex to do is return 100 matches, but what it is doing is returning one match that is the entire string.

What am I doing wrong?

0
Comment
Question by:pamsauto
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
ddrudik earned 500 total points
ID: 22668908
Dim regPart As New System.Text.RegularExpressions.Regex(Chr(128) + ".*?" + Chr(129))
0
 

Author Comment

by:pamsauto
ID: 22668950
Thanks!
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 22668980
Thanks for the question and the points.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question