What strings are matches by
Daisy|Daisies
The regular expression matches:
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.
Which output do you think the program produces?
Matches Does not match