Search code examples
c#regexstrip

How can I get the string between two tags


I wonder how to get a string (or array of strings) between two known tags. For example I have this string

string var1="my first video is [video]http://video.com/aaa[/video] and my second is[video id=\"1\" length=\"3\"]http://video.com/bbb[/video]";

How to get these values http://video.com/aaa and http://video.com/bbb?


Solution

  • use this pattern: @"\[video.*?\](.*?)\[/video\]" and then get group 1. I won't post the whole code because I dont want to do your work for you. Read about C# Regexes, Patterns and try to write your code with this pattern.