In: Computer Science
Describe the languages specified by the following regular expressions:
1. \\(_+)/
2. (\(740\)...-...)|(...-...) (The alphabet is {1,2,3,4,5,6,7,8,9,0})
1.The first regular expression is \\(_+)/
\ is an escaping character which is used to escape a special character.So here // means / in the string will be matched.
Inside the bracket (), _+ is present. + implies matching one or more occurrence of the previous character . Therefore, _+ means matching one or more occurence of _ (underscore ) in the string.
/ denotes the end character will be match to /.
From the above details we can conclude that the given regular expression will matches strings like,
\_/, \__/, \___/, \____/, etc.
2.The second regular expression is (\(740\)...-...)|(...-...)
\ is an escaping character which is used to escape a special character.So here \( matches ( of the string.
740 will be matched to 740 in the string
\) will matches ) in the string
. means any character except newline character will be matched .Here three dots are present.So... denotes the string will get matches to any 3 characters other than newline.
- will matches the - in the string
Therfore (\(740\)...-...) means, this regular expression matches to the string contain (740) then any 3 characters other than newline then - (hyphen) and then any 3 characters other than newline.
(...-...) means this regular expression matches the to the string contain any 3 characters other than newline and hyphen - and any 3 characters other than newline.
The given regular expression is, (\(740\)...-...)|(...-...) which means (\(740\)...-...) or (...-...)
So there is many combination of strings which matches the given regular expression. Some of examples are,
(740),78-91'
218-702
(740)13>-076
1:}-517