2

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

1
  • Have you tried doing a simple replace of the characters that you don't want with an empty string? Commented May 14, 2014 at 15:55

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, the pattern is fixed - with the exception of Person: - this could say other things such as "team", "page"
1

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");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.