[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
- <!--x-content-type: text/plain -->
- <!--x-date: Sat, 13 Aug 2005 16:48:36 -0400 -->
- <!--x-from-r13: psbjyre ng bhgcbfgfragvary.pbz (Quevfgbcure Tbjyre) -->
- <!--x-message-id: [email protected] -->
- <!--x-reference: [email protected] -->
- <!--x-reference: 1123891371.12776.0.camel@localhost -->
- <!--x-reference: [email protected] -->
- <!--x-reference: [email protected] -->
- <!--x-reference: [email protected] -->
- <!--x-reference: [email protected] --> "http://www.w3.org/TR/html4/loose.dtd">
- <!--x-subject: [ale] Yet another regex question -->
- <li><em>date</em>: Sat, 13 Aug 2005 16:48:36 -0400</li>
- <li><em>from</em>: cfowler at outpostsentinel.com (Christopher Fowler)</li>
- <li><em>in-reply-to</em>: <<a href="msg00155.html">[email protected]</a>></li>
- <li><em>references</em>: <<a href="msg00130.html">[email protected]</a>> <1123891371.12776.0.camel@localhost> <<a href="msg00132.html">[email protected]</a>> <<a href="msg00133.html">[email protected]</a>> <<a href="msg00154.html">[email protected]</a>> <<a href="msg00155.html">[email protected]</a>></li>
- <li><em>subject</em>: [ale] Yet another regex question</li>
[cfowler at shuttle ~]$ ./regex.pl '([^%].|\S)XMI001' 'XMI001'
No
[cfowler at shuttle ~]$ ./regex.pl '([^%].|\S)XMI001' ' XMI001'
Yes
Maybe I'm doing it wrong?[cfowler at shuttle ~]$ cat regex.pl
#!/usr/bin/perl
die "regex.pl <regex> <test string>\n" unless $ARGV[0] and $ARGV[1];
my $regex = $ARGV[0];
if($ARGV[1] =~ m/$regex/) {
print "Yes\n";
} else {
print "No\n";
}
The only reason I'm using perl this way is to test the regex.
On Sat, 2005-08-13 at 15:42 -0400, Stephen Cristol wrote:
> On Aug 13, 2005, at 2:25 PM, Stephen Cristol wrote:
> > On Aug 12, 2005, at 9:29 PM, Christopher Fowler wrote:
> >> I guess what I'm asking is if there is a way to catch 'XMI001' instead
> >> of '%\sXMI001' without using the anchors
> >
> > Probably not. The following perl regex will catch most of what you
> > want:
> >
> > /[^%]\S$signal/
>
> Maybe I can get it right on the second try:
>
> /([^%].|\S)$signal/
>
> This also has the minor benefit of eliminating the special case when
> the signal offset from the beginning of the string is 1.
>
> S
>
> > where $signal is "XMI001", the caret is a negation rather than an
> > anchor, and the "\S" (uppercase "S") matches a character that is not
> > whitespace. (NB: if $signal contains regex metacharacters, it will
> > probably need to be enclosed in parentheses.)
> >
> > This misses the signal when it occurs at offset 0 or 1 from the
> > beginning of the string. A potentially easy fix for this (which may not
> > be an option in your environment) is to prepend two spaces to the
> > beginning of every string processed. That guarantees that there will be
> > enough leading characters for the above regex to match the signal
> > wherever it occurs in the string.
>
>
</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<ul><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><a name="00157" href="msg00157.html">[ale] Yet another regex question</a></strong>
<ul><li><em>From:</em> joe at madewell.com (Joe Steele)</li></ul></li>
</ul></li></ul>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00130" href="msg00130.html">[ale] Yet another regex question</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Christopher Fowler)</li></ul></li>
<li><strong><a name="00131" href="msg00131.html">[ale] Yet another regex question</a></strong>
<ul><li><em>From:</em> jimpop at yahoo.com (Jim Popovitch)</li></ul></li>
<li><strong><a name="00132" href="msg00132.html">[ale] Yet another regex question</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Christopher Fowler)</li></ul></li>
<li><strong><a name="00133" href="msg00133.html">[ale] Yet another regex question</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Christopher Fowler)</li></ul></li>
<li><strong><a name="00154" href="msg00154.html">[ale] Yet another regex question</a></strong>
<ul><li><em>From:</em> stephen at bee.net (Stephen Cristol)</li></ul></li>
<li><strong><a name="00155" href="msg00155.html">[ale] Yet another regex question</a></strong>
<ul><li><em>From:</em> stephen at usersouth.com (Stephen Cristol)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00155.html">[ale] Yet another regex question</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00157.html">[ale] Yet another regex question</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00155.html">[ale] Yet another regex question</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00157.html">[ale] Yet another regex question</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00156"><strong>Date</strong></a></li>
<li><a href="threads.html#00156"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>
<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>