On 01/31/2011 10:44 AM, Steve Wampler wrote:
> My recommendation is that you (rhetorically, again) not try to approach
> string scanning by trying to map RE's into scanning expressions, but to
> ask what a specific RE is trying to do and then trying to think of a way
> to accomplish the same specific task using scanning *without* considering
> how that task was done using an RE.
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.
Anyway, here's an example:
----------------------------------------------------------------
procedure main()
# 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
# A 'pattern' that matches "foo" and "baz" separated by
# exactly one character anywhere in the subject string
procedure pat()
suspend (tab(upto('f')), (="foo"||move(1)||="baz"))
end
---------------------------------------------------
and a sample run:
---------------------------------------------------
->t
foo baz
match found
foo:baz
foo?baz
->
----------------------------------------------------
--
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