Question

I have a string like so "blah blah blah blah @[Dave Battersby](Person:292) blah blibbidy blah"

I want to strip out the unreadable parts so just the text remains using a regular expression. I have tried this regular expression (?<=\[)(.*?)(?=\]) but this just gives a collection of the things inside the [] Ie Dave Battersby

What I need is to return the string "blah blah blah blah Dave Battersby blah blibbidy blah"

Thanks

Was it helpful?

Solution

It's not entirely clear if the pattern @[name](id info) is fixed, but if so, the following should work:

Dim input = "blah blah blah blah @[Dave Battersby](Person:292) blah blibbidy blah"
Dim output = Regex.Replace(input, "@\[(.*?)\]\(.*?\)", "$1")

This searches for the full pattern, capturing the name part, and replaces the matched text with just the name.

OTHER TIPS

Assuming there are no square brackets or parenthesis in your "blah blah blah" text, the following should work:

string myStr = "blah blah blah blah @[Dave Battersby](Person:292) blah blibbidy blah";
Regex.Replace(myStr, @"@\[(.*)\].*\)", "$1");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top