in reply to Re: Re: An "ethical" use of dot-star ..?
in thread An "ethical" use of dot-star ..?

What does that gain, though, over .*??

It better expresses what you are actually trying to do. (I''m actually not entirely sure that's true in your case, but it may be.)

For one, using [^<]* will match a newline. Your original regex will not. You'd have to use a /s modifier for that.

On the other hand, using [^<]* will simply fail to match on strings like: "<inequality>X < Y</inequality>" but maybe that's fine in your case.

By the way, yours will fail if there is a space between the '<' and the '/' in the end tag. Maybe you knew that though.... if that's what you wanted, it's fine.

And that's really the crux of the matter. There is nothing inherently wrong in using a dot-star. It's just misunderstood so often that it's prudent to warn people about it. The other day, I recommended someone use my ($file, $ext) = /(.*)\.(.*)/; to break a filename into its base and extension. Two dot-stars for the price of one there... but — shrug — it did what he needed. The key is understanding what you need and how best to express it. Don't say "zero or more (but as few as possible) of any character except a newline" when you really mean "as many non-Less-Than characters as possible."

-sauoq
"My two cents aren't worth a dime.";
  • Comment on Re: Re: Re: An "ethical" use of dot-star ..?