Jean-Claude Terrier <jterrier sogetra.com> wrote:
>
>Allen,
>
>Thanks for looking at my problem.
>I have some control over how the text could be
manipulated
>in order to make it easier to develop a solution.
Ok, going by the examples in this e-mail -- assuming the
data is truly that
predictable, then it wouldn't in fact be that difficult to
achieve this.
The question is whether or not it is possible to predict
where the
tokenless value will be. The examples you sent had
like-formatting, which
makes this pretty easy to work with. If the token is
literally TOKEN or
something qually predictable, it would be handled like this:
Find:
(.+?) (TOKEN)
(.+?) (?!TOKEN)
You could also use
(.+?) (TOKEN)[\r\n]+(.+?) (?!TOKEN)
to put it on a single line.
Replace:
$1 $2
$3 $2
Or single line
$1 $2\n$3 $2
-- that will find occurrences where there is any text
followed by token on
one line and then any text not followed by a token on the
next line. It
will replace it with the proper text and the token following
each. This
could be more complicated, though, if the token is less
obvious -- but
probably still possible.
The potential caveat with this particular method is that if
there are
multiple lines in a row with no token, then you'd have to
run this replace
multiple times -- each time the token would be carried to
the next line --
slowly replacing them all a line at a time.
>2) Would it be easier if the multi-line strings were
converted
>into single line strings (with or without end marker,
such as
>
>value=ddd0 text TOKEN text TOKEN (...) text [endval]
>value=ddd1 text TOKEN text TOKEN (...) text [endval]
>value=ddd2 text TOKEN text TOKEN (...) text [endval]
If you're literally dealing with lines formatted as such
(I'm not sure what
happens in the (...) part, you could simply
^value=([a-z0-9]) (.*?) (TOKEN) (.*?)
If this won't work, if you could provide a more detailed
specification or
example of the data we're working with on or off list, it
may help. I'm
only vaguely understand the data I'm trying to parse ;)
--
Remember, no matter where you go, there you are. -Buckaroo
Banzai
|