> 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 :)
> in order, but NOT match the empty string, and NOT match out of order
> strings like
> bac
> Is there a succinct way to express this, or do I have to do
> a|b|c|ab|ac|bc|abc
I am not sure that "ac" is a substring of "abc", though ...if you
insist...
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!" :)
> > Is there a succinct way to express this, or do I have to do
> > a|b|c|ab|ac|bc|abc
> I am not sure that "ac" is a substring of "abc", though ...if you
> insist...
> 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!" :)
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
where \A and \Z are start of input and end of input anchors.
> Reducing it to a simpler problem, I want to match any substring of
> abc
> in order, but NOT match the empty string, and NOT match out of order
> strings like
> bac
> Is there a succinct way to express this, or do I have to do
> a|b|c|ab|ac|bc|abc
> Thank you.
If you have set difference operation ('-') and epsilon string ('e')
Then you can write abc - e.
I am developing a tool for generating finite state machines from
regular expression. I will be implementing a not empty operator
('!').
With it you could write (abc)!
So there should be an easy way to do what you want but I'm guessing
it is not available on the system you are using.
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.
On Oct 12, 4:14 pm, Ralph Boland <rpbol...@gmail.com> wrote:
> If you have set difference operation ('-') and epsilon string ('e')
> Then you can write abc - e.
I'm not familiar with those things ... as I mentioned to Accmailer
above, a b and c are to
be considered regex particles, not single characters. I don't know if
that changes your answer.
> I am developing a tool for generating finite state machines from
> regular expression. I will be implementing a not empty operator
> ('!').
> With it you could write (abc)!
> So there should be an easy way to do what you want but I'm guessing
> it is not available on the system you are using.
Probably not. I found a workaround by prefixing my test string as
well as the regex.