Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

How to check either of the two strings?

Last post 08-14-2008, 2:44 AM by Aussie Susan. 1 replies.
Sort Posts: Previous Next
  •  08-08-2008, 9:20 PM 45154

    How to check either of the two strings?

    I want to check for either of the two strings. (At any time, there can be only one string present on the page)

     

    String1: Results <SPAN id=ctl00_C_TopPagination_lblRecordsShowing>1 - [0-9][0-4]*</SPAN> of <SPAN
    id=ctl00_C_TopPagination_lblTotalRecords>[0-9]+</SPAN> for
    <DIV class=searchbreadcrumb>${resultpage} </DIV>

    String2: No results were found for ${resultpage}. Please try again.

     

    Note: resultpage is a variable.

     

    Thanks,

  •  08-14-2008, 2:44 AM 45338 in reply to 45154

    Re: How to check either of the two strings?

    If you want to do both checks simultaneously, then use alternation:

    string1|string2

    If I interpret your question correctly, then you will want to create your string with something like the following pseudo-code:

    Pattern = "Results\s+<span" + ResultPage + "</div>|No\s+results\s+" + ResultPage + "\s+found\."
    Result = Regex.Match(Pattern, String, Options)
    if(Result) then
    {
        // Found one of the text strings
    }
    else
    {
        // Neither text string found
    }

    Of course, you will need to create the pattern correctly for your language and regex engine etc.

    If you want to also ensure that only one of the strings occurs, then you should either search for both strings separately and use some program logic to check that only one exists (XOR???) or get back to us with some real examples (see the posting guidelines on the 'Construction Advice' forum on this site) and we might be able to help you further.

    Susan

     

View as RSS news feed in XML