Skip to content

Instantly share code, notes, and snippets.

@windwp
Last active September 27, 2017 11:47
Show Gist options
  • Save windwp/8b93e5773209e9f28272 to your computer and use it in GitHub Desktop.
Save windwp/8b93e5773209e9f28272 to your computer and use it in GitHub Desktop.
try {
Regex regexObj = new Regex(@"library/(\d*)", RegexOptions.Multiline);
resultString = regexObj.Match(subjectString).Groups[1].Value;
Console.WriteLine(resultString);
} catch (ArgumentException ex) {
// Syntax error in the regular expression
Console.WriteLine(ex.StackTrace);
}
C# YouTube regex
var youtubeid = Regex.Match(videoUrl,
@"^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*")
.Groups[7].Value;
// remove any tags but not there content "<p>bob<span> johnson</span></p>" becomes "bob johnson
Regex.Replace(input, @"<(.|\n)*?>", string.Empty);
//remove tags with content "<p>bob<span> johnson</span></p>" becomes ""
<.*\s*/?>
//remove only specific tag
<%TAG%[^>]*>(.*?)</%TAG%>
<a[^>]*>(.*?)</a>
//remove all tag except br tag
(?!<\/?br\s*\/?>)<[^>]+>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment