Re: How to spell out Roman numerals


Luke Davis
 

On Sat, 7 Nov 2020, Brian Vogel wrote:

[Regarding my question about the use of \s?]
My thinking it that there can be no whitespace after the colon, or an instance of a single whitespace character, but not multiple whitespace characters. 
Definitely not the same as .* at all.
Are you sure? Just using egrep -e on my local machine, all of the following expressions will match the string "test":

.*st
te.*
\s?st
te\s?

I agree that one could probably use \b, but I was thinking "whitespace" and used whitespace matching.
I understand why whitespace might be interesting there. But searching for it as optional, without an anchor or pre/post text, is the same as not searching for it at all.

It is an old truism in regex building, that if your match potentially includes zero of something at the start or end of an expression, it may as well not be there unless there is an anchor.

For example, my tests above, rewritten as:

^\s?st
te\s?$

would fail as they should. But the naked zero space matches in the originals function exactly as a full wildcard (.*).

Luke

Join nvda@nvda.groups.io to automatically receive all group messages.