Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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...

  • Leaders
Posted

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 :).

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

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

  • 2 years later...
Posted

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...

  • Leaders
Posted
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.
[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...