Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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 ".*"

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote