On Oct 7, 2:38 am, Accmailer <
eugeny.satt...@gmail.com> wrote:
> > Reducing it to a simpler problem, I want to match any substring of
>
> > abc
>
> Frankly speaking i did not quite get how the first question transforms
> into the second one :)
"a", "b" and "c" are to be considered markers for regex pieces, not
just characters. so, matching something like
12y13d
is equivalent to matching
ac
where
a = [0-9]+y
b = [0-9]+m
c = [0-9]+d
> I am not sure that "ac" is a substring of "abc", though ...if you
> insist...
substring is perhaps a bad word for the concept ... what's meant is a
string composed of optional elements that must be in a certain order,
where each element is optional but at least one element must be used.
> a?b?c?
> can be a more elegant expression.
> It will match all things you listed: "a" or "b" or "c" or "ab" or "ac"
> or "bc" or "abc".
> Problem: it will match zero length string and report "FOUND!" :)
Exactly -- that was what led me to post in the first place.
> Just now an idea got into my mind: Thу abovementioned problem can
> be solved via positive lookahead requiring at least one letter
> to be present. This way:
> \A(?=\w+)a?b?c?\Z
That's probably the concept I hadn't thought of -- positive
lookahead. Thanks for that.
In the final event, I solved my problem by adding a prefix character
to the string to be matched. So
instead of matching "ac" with /a?b?c?/
I am matching "xac" with /xa?b?c?/
This is probably less expensive than positive lookahead, and it's
easier to document in any case.