On 01/31/2011 11:39 AM, Steve Wampler wrote:
> Incidentally, it is possible to mimic some of the fundamental approach
> used with RE's directly in string scanning, but it's not obvious. You
> can build 'scanning procedures' that can be used in a manner analogous
> to applying a RE pattern. It's not regularly done, so I'm not sure it's
> that useful of an approach. For one thing, it isolates the scanning
> aspect of string processing from the actions you want to perform on
> the string, making it harder to build an integrated solution.
And, just because I'm feeling perverse today, you can express the
'pattern' as a one-liner using co-expressions!:
--------------------------------------------------------------
procedure main()
# construct a 'pattern' matching "foo" and "baz" separated
# exactly one character (produces the matched substring)
pat := create (tab(upto('f')), (="foo"||move(1)||="baz"))
# Try it out:
"foo baz bar" ? write(@^pat)
"bar foo baz foo@baz" ? {
if @^pat then write("match found")
else write("no match")
}
"bar foo:baz a foo?baz" ? {
while write(@^pat)
}
end
-----------------------------------------------
(There's subtle performance hit with this approach, since
the co-expression has to be refreshed all the time...)
--
Steve Wampler -- [email protected]
The gods that smiled on your birth are now laughing out loud.
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires
February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Unicon-group mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/unicon-group