Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6871333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:47:34+00:00 2026-05-27T03:47:34+00:00

I have the following two patterns and need to find a match if either

  • 0

I have the following two patterns and need to find a match if either or is found in a string and then move onto the next match.

for one pattern i’ve been using

 MatchCollection m0 = Regex.Matches(file, @"<ul class=""Information"">[\s\n\t.]+<img src=""http://test/images/I/test.gif"">",
                   RegexOptions.Singleline);

then looping through the matches and extracting the details I need

The second pattern I need is

MatchCollection m1 = Regex.Matches(file, @"<ul class=""Information"">[\s\n\t.]+ <a href=""http://www.test.com/test/""\w+",
                   RegexOptions.Singleline);

Is it possible in regex to combine these into one search, using an OR for example?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:47:35+00:00Added an answer on May 27, 2026 at 3:47 am

    Disclaimer

    For the haters out there, this isn’t neccesarily a Parsing HTML with Regex Question. The root of his question is he’s looking for the Disjunction functionality in a regex.

    Solution

    While @dtb may be right about regex with html, for simple cases (small inputs & simple patterns) it’s not neccesarily a bad idea if you know when to use it.

    This is a simple solution in regex.

    string pattern = @"<ul class=""Information"">[\s\n\t.]+" +
                     @"(?:<img src=""http://test/images/I/test.gif"">|" +
                     @"<a href=""http://www.test.com/test/""\w+)";
    
    MatchCollection m0 = Regex.Matches(file, pattern, RegexOptions.Singleline);
    

    What’s been done here @Paul is we’ve taken the two trailing components of your matches and put them into a non-capturing group: (?: ). This makes sure it won’t mess with your capture groups, but you’re welcome to capture it if you need to.

    From here we use the OR operator | to split the group into capturing either one or the other.

    (?:<img src="http://test/images/I/test.gif">|<a href="http://www.test.com/test/"\w+)
    

    This is the resulting pattern match for the 2nd part.

    Note: If you are doing this more than once in a while (i.e. a loop) you should compile your regex, it’ll execute faster.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to wrap one div around another? I have following two div ids: #course
I have the following two projects in in Flex Builder 3: One AS3 library
I have the following two classes, one inherits from the other Class A{ void
I have the following urls that need mapping to two different servlets. Can anyone
I have two Windows services written in C# following the same patterns and methodology.
I have the following possible string patterns (whitespace is variable): 2-4 Jun 8-11 Jun
I have a structure similar to the following: /root/ /root/data/ /root/data/script.php /root/data/some.json /root/data/feature/one.json /root/data/feature/two.json
I have following two arrays. I want the difference between these two arrays. That
I have the following two columns: SELECT b.ip_address AS IP ,b.mask AS MASK FROM
I have the following two tables, affiliates and referrers. affiliates Table id loginid 3

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.