TruMan1
TruMan1

Reputation: 36118

Regex for handling values with surrounding characters?

I would like to convert values in a string with surrounding || symbols. For example, ||more info|| would have to be changed to <a href="#">more info</a>. How do I do this while leaving the text in the middle ("more info" can be anything else)?

Upvotes: 2

Views: 388

Answers (1)

mroach
mroach

Reputation: 2468

This is probably the simplest way to do what you want:

var pattern = @"\|\|(.+?)\|\|";
var replacement = @"<a href=""#"">$1</a>";
var input = "you can get ||more info|| here";

var result = Regex.Replace(input, pattern, replacement);
Console.WriteLine (result);

Upvotes: 1

Related Questions