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

Answer:

Yes. If the alphabet is ASCII, then the character '#' is matched by [^0-9]


Basic Regular Expressions: Zero or One

Regular Expression
(Delimit with quotes)
String
(Delimit with quotes)

Rule 5. Zero or One Instance

When a character is followed by ? in a regular expression it means to match zero or one instance of the character. So X? matches an 'X' if there is one in the string, but otherwise matches nothing.

Regular ExpressionMatches
a?bcabcbc
colou?rcolorcolour
computers?computercomputers
A?AØ

The Ø in the above table means that the regular expression A? matches the empty string — the string that contains no characters.

? can be used following a range of characters or an exclusion range, in which case it means to optionally match one or zero characters from that range.

Regular ExpressionMatches
[a-z]?[1-9]a11z9
WX[^AB]?WXWXCWXY
[0-9]?[0-9]?[1-9]00705 9

QUESTION 14:

Which of the following strings match [BD][ae][ae]?d     ?

StringBedBeadDeadaedBa?dDedBea
Match or
Reject?

Write a RE that matches the strings Ba?d , Be?d , De?d , and Da?d (these are strings, not patterns, and the question mark is part of the string).