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

有帮助吗?

解决方案

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.

其他提示

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");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top