go to previous page   go to home page   go to next page

What strings are matches by Daisy|Daisies

Answer:

The regular expression matches:


Example Program

Here is a (rather silly) program:

class TestString
{
  public static void main ( String[] args )
  {
    String test = "Daisy";
       
    String RE = "Daisy|Daisies";

    if ( test.matches( RE ) )
      System.out.println( "Matches" );
    else
      System.out.println( "Does not match" );
  }
}

The method call

test.matches( RE )

runs the matches() method of the String object referenced by test. It returns true if the string matches the regular expression RE, otherwise it returns false.


QUESTION 2:

Which output do you think the program produces?

Matches

Does not match