[ale] Yet another regex question

Stephen Cristol stephen at usersouth.com
Sat Aug 13 15:42:43 EDT 2005


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.


-- 
Stephen Cristol
cristol at emory.edu




More information about the Ale mailing list