문제

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