Vijay Sharma
Vijay Sharma

Reputation: 373

How to I parse custom tags this string using regex

I need to parse a string which contains custom tags like [link][description][link-url][/link] and I want to convert it to <a href="link-url">description</a>. Any help on this is highly appreciated.

Upvotes: 0

Views: 478

Answers (1)

Justin Pihony
Justin Pihony

Reputation: 67075

Here is the regex you could use:

\[link\]\[(.*)\]\[(.*)\]\[\/link\]

Then you can use the regex replace:

<a href="$2">$1</a>

Upvotes: 2

Related Questions