L
L
lightalex2015-10-13 01:10:25
PHP
lightalex, 2015-10-13 01:10:25

How to remove all comments from a string using regular expressions in php?

Hello!
I'm learning regular expressions.
Decided to remove multi-line comments from the string - /* blah blah blah */
Compiled the wrong regular expression - /(\*).*(\*)/
Now he is looking for the first and last occurrences * and deletes everything between them
And he does not care what else is there a bunch * in the piece that he demolished (
Well, it remains //
Cant on the jamb, help the crooked hand :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2015-10-13
@lightalex

stackoverflow.com/questions/643113/regex-to-strip-...

K
Kjuri, 2015-10-13
@Kjuri

greed of quantifiers - dig here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question