hammerman Posted January 16, 2004 Posted January 16, 2004 okay.. I'm not the best at writing reg exp so I'm sure this is simple but I've tried it a hundred different ways... Given a string I want to pull out the first occurance of all characters,digits,spaces and special chars between the [ and ] for instance I usally have a string such as "[blah boo & foo] + [heeee]" I want to return "[blah boo & foo]" below is my feable attempt to get this... Dim r As Regex = New Regex("\[.*\]") Dim m As Match = r.Match(stringGoesHere) Dim basdf As String = m.Value "\[.*\]" is somewhat sucessful.. but it returns the whole string (obviously because the string starts and ends with [ ]. So I try something like \[\w*\s*\] and that only works for something like [booo] no [boo foo]. I guess I'm stuck in the middle portion where I want everything between the [].. any help is much appreciated... Quote
Leaders Iceplug Posted January 17, 2004 Leaders Posted January 17, 2004 Try Pattern = "((?<=\[)[^\[\]]*)" The (?<=\[) skips until it finds a [ ( \[ ) The [^\[\]] picks up characters after the [ that is not a [ or ]. ( \[ , \] ) Also, you can make your own little app that will test your RegEx expressions... you only need two TextBoxes and a Button :). Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
hammerman Posted January 17, 2004 Author Posted January 17, 2004 Works like a charm! thanks - that works like a charm!!! One thing I love about reg exp is how elegant it is to write a complicated match pattern.. just wish I was better at doing them :D Quote
nbrege Posted February 28, 2006 Posted February 28, 2006 Also, you can make your own little app that will test your RegEx expressions... you only need two TextBoxes and a Button :). Iceplug ... you have any code for this test app? I think it would be a good way for me to learn regular expressions. Thanks... Quote
Leaders snarfblam Posted February 28, 2006 Leaders Posted February 28, 2006 I think IcePlug was simply suggesting that you create a project with a form that contains something like a few textboxes and button. Enter text to be searched into TextBox1, enter a search pattern in TextBox2, and when the user clicks the button, output the results in TextBox3. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.