[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: grep / sed + regex : possible bug ?



Hi Colin
That makes it way clearer now.

So I am safe to assume that the regexes used in sed / grep et. al. are
quite different from those encountered in automata theorie?
For a DFA / NFA, regular languages and regexes describe the same stuff,
and unless im mistaken
Be sigma the alphabet conatining all characters allowed in a *nix file
AND the {/}
Sigma*/Name/(Sigma \ {/})(Sigma \ {/})* would match
any string (emopty string included) over Sigma followed by /Name/
followed by at least one (or up to infinitley) many letters in Sigma
except the {/}

> No, you misunderstand. Your regular expression matches "/Name/" followed
> by one or more non-/ characters. It says nothing about what is allowed
> to follow those non-/ characters. If you want the non-/ characters to
> extend until the end of the line - that is, you want no / characters
> until the end of the line - you *must* anchor the regular expression
> using a final $.
...
> You've definitely misunderstood how unanchored regular expressions work.
> In general, tools that handle regular expressions do *not* require them
> to match all the input, so your "state invalid" actually means "we ran
> off the end of the regular expression before we ran out of input, but
> that's OK".

So in fact it (my regex) is taken as
.*/Name/[^/][^/]*.*
(note the additional .*) as long as I don't and quite clearly say it has
to stop, i. e. add an anchor.

Thanks for the help

Axel Schlicht



Reply to: