[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
- <!--x-content-type: text/plain -->
- <!--x-date: Fri Mar 12 10:43:32 2004 -->
- <!--x-from-r13: psbjyre ng bhgcbfgfragvary.pbz (Quevfgbcure Tbjyre) -->
- <!--x-message-id: [email protected] -->
- <!--x-reference: 1079063828.9310.19.camel@devel -->
- <!--x-reference: [email protected] -->
- <!--x-reference: [email protected] -->
- <!--x-reference: [email protected] -->
- <!--x-reference: 1079066551.4813.4.camel@devel -->
- <!--x-reference: [email protected] --> "http://www.w3.org/TR/html4/loose.dtd">
- <!--x-subject: [ale] Regex question -->
- <li><em>date</em>: Fri Mar 12 10:43:32 2004</li>
- <li><em>from</em>: cfowler at outpostsentinel.com (Christopher Fowler)</li>
- <li><em>in-reply-to</em>: <[email protected]></li>
- <li><em>references</em>: <1079063828.9310.19.camel@devel> <<a href="msg00366.html">[email protected]</a>> <<a href="msg00367.html">[email protected]</a>> <<a href="msg00368.html">[email protected]</a>> <1079066551.4813.4.camel@devel> <[email protected]></li>
- <li><em>subject</em>: [ale] Regex question</li>
On Fri, 2004-03-12 at 02:41, Joe Knapka wrote:
> Chris Fowler <cfowler at outpostsentinel.com> writes:
>
> > On Thu, 2004-03-11 at 23:34, Mike Murphy wrote:
> > > ah, yeah, stuff like awk won't know what \d is. Try this:
> > >
> > > echo XMI313 | awk '/XMI[0-9][0-9][0-9]/ {print $0}'
> > >
> > I think this is the first one that would be required.
> >
> > > this is a little neater:
> > >
> > > echo XMI333 | awk '/XMI[0-9]+/ {print $0}'
> > >
> >
> > If I did XMI0 then the string would hit. The remaining 01 would be
> > ignored by the program.
>
> No. REs are (almost always) greedy by default. However, it would match
> the lone string "XMI0", as well as the string "XMI0123", which you
> apparently don't want. To get exactly what you want you can use
>
> (XMI([0-9]{3})?)
>
> Which says, "XMI, possibly followed by exactly three occurrences of a
> decimal digit." Or if your regexp engine doesn't understand {}, just
> explicitly repeat the [0-9] three times:
>
> (XMI([0-9][0-9][0-9])?)
>
> The above RE should work everywhere REs are spoken. Both of these
> have the effect of creating an extraneous capture group, which might
> cause problems in some contexts. Perl-compatible REs have a syntax for
> a non-capturing group, but I don't remember it offhand. It's something
> like
>
> (XMI(:?[0-9]{3})?)
>
> I think.
>
> -- Joe
>
> That would be an unanticipated consequence.
> > So an error code is basically a few letters followed by numbers. The
> > letters represent a group and the numbers represent a specific error
> > condition. I'm trying to group them to reduce load on the program. I
> > have to search for 1000 possible errors.
> >
> >
> > > but could have unanticipated consequences. For instance, if you do that
> > > with an input of something like 'XMI3334', its going to find that, but
> > > that's also true of the first example. (because the substring matched.
> > > That's probably ok for your purposes. If not, you might try anchoring
> > > that with a ^ and a $ if necessary (assuming that would work for your
> > > stream).
> > >
> > > Mike
> > >
> > >
> > > Christopher Fowler wrote:
> > > > On Thu, Mar 11, 2004 at 11:13:04PM -0500, Mike Murphy wrote:
> > > >
> > > >>unless I'm missing something, something like this:
> > > >>
> > > >>=~ /(XMI\d\d\d)/ should work. The entire string matched will show up in
> > > >>$1 afteward. This presumes that not other characters will show in the
> > > >>string.
> > > >
> > > >
> > > > I must be doing something wrong then, I'm using AWK to validate the regex.
> > > > The perl Expect module will actually do the matching based on the regular
> > > > expression so I do not think anything that is perl specific will work. That
> > > > is why I'm testing with awk
> > > >
> > > > echo XMI | awk '/XMI\d\d\d/ {print $0}'
> > > >
> >
> > _______________________________________________
> > Ale mailing list
> > Ale at ale.org
> > <a rel="nofollow" href="http://www.ale.org/mailman/listinfo/ale">http://www.ale.org/mailman/listinfo/ale</a>
> >
> >
</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00369" href="msg00369.html">[ale] Regex question</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Chris Fowler)</li></ul></li>
<li><strong><a name="00366" href="msg00366.html">[ale] Regex question</a></strong>
<ul><li><em>From:</em> mike at tyderia.net (Mike Murphy)</li></ul></li>
<li><strong><a name="00367" href="msg00367.html">[ale] Regex question</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Christopher Fowler)</li></ul></li>
<li><strong><a name="00368" href="msg00368.html">[ale] Regex question</a></strong>
<ul><li><em>From:</em> mike at tyderia.net (Mike Murphy)</li></ul></li>
<li><strong><a name="00371" href="msg00371.html">[ale] Regex question</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Chris Fowler)</li></ul></li>
<li><strong><a name="00375" href="msg00375.html">[ale] Regex question</a></strong>
<ul><li><em>From:</em> jknapka at kneuro.net (Joe Knapka)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00383.html">[ale] Free Zombie PC parts</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00385.html">[ale] [OT] Action Update: Georgia SB 500 VVPB Legislation</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00375.html">[ale] Regex question</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00373.html">[ale] PPP autodial in Fedora</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00384"><strong>Date</strong></a></li>
<li><a href="threads.html#00384"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>
<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>