Regex Question - Beginner

I have the following question extracted from a tutorial:

Write RE to describe comments consisting of a line surrounded by / * and * / without alternating / * or * / if it does not appear between quotation marks ""

Here is my attempt:

^/[*].*(".*(/[*].*[*]/)*.*")*[*]/$

EDIT:

I used:

http://gskinner.com/RegExr/

It works as follows:

/* This is "/* a */" comment */fdgh

It's hard for me to debug a regex. Can you tell me where I will be if this is not true.

+2
source share
1 answer

Difficult, after some time I came up with this solution. It has been tested using the raster regular expression constructor .

^/\*((?!.*(\*/|/\*).*\*/)[^"]*)|((?![^"]*?(\*/|/\*)")[^"]*"[^"]*"(?![^"]*?(\*/|/\*).+)[^"]*)+\*/$
0
source

All Articles