amateur
amateur

Reputation: 44605

combine regular expression

I have two regualar rexpressions I would like to combine into the one for performance games but unsure how to achieve. The first expression finds all the images in html, the second, finds all input buttons of type image.

  1. Regex.Matches(html, @"<img[^>]*?src\s*=\s*[""']?([^'"" >]+?)[ '""][^>]*?>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
  2. Regex.Matches(html, @"<input[^>]*?src\s*=\s*[""']?([^'"" >]+?)[ '""][^>]*?>", RegexOptions.IgnoreCase | RegexOptions.Singleline);

How could I combine these?

Upvotes: 0

Views: 1022

Answers (2)

honibis
honibis

Reputation: 811

You should consider using Html Agility Pack to parse html documents fastly and correctly:

http://htmlagilitypack.codeplex.com/

Upvotes: 1

amcashcow
amcashcow

Reputation: 734

The way you've written it is a little ambiguous...but from what I can tell you want a list that contains both images and input buttons of type image. (not sure what u mean by input button of type image?

so you can put brackets and an or in between

ie.. (regex1|regex2)

depending how specific the contents of the tags is you could also have something like

<(?:img|input)[^>]*?src\s*=\s*[""']?([^'"" >]+?)[ '""][^>]*?>

Upvotes: 0

Related Questions