質問

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