Write a regular expression to describe each of the following programming languag
ID: 2246780 • Letter: W
Question
Write a regular expression to describe each of the following programming language constructs:
(a) Any sequence of tabs and blanks (sometimes called white space). Use for tab, and require at least one space or tab.
(b) Comments in the C programming language. Recall that the only kind of comment in C /* looks like this */.
(c) String constants (without escape characters). An example would be to match “abcd” (with double-quotes). It does not need to support double-quotes inside the string. You only need support alphabetic characters inside the double-quotes.
Explanation / Answer
a) [ ]*
b) /*([^*]|[ ]|(*+([^*/]|[ ])))**+/
c) Double quotes don't have special meaning in regex, hence they can be directly matched as ".*", but if you are enclsoing this expression in some string in some language which keeps string enclosed in double quotes itself(like c++, Java) then you need to mark them with backslashes like ".*"
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.