List Info

Thread: Rgex to insert variable value in text




Rgex to insert variable value in text
user name
2006-02-14 20:24:58
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.

1) would it be easier if the multi-line string was marked at
the end, like so :

value=dddd
text TOKEN
text TOKEN
text no token
(...) text
endval
Note : value is always 4 digits

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]

I am hoping for more help on this.

Thanks in advance

JCT



Le 2006-02-09, à 18:54 GMT-0500, Allen Day écrivait :

On 2/9/06, Jean-Claude Terrier <jterriersogetra.com> wrote:
>
> Hello everyone,
>
> I have lists in the form of
>
> value=1664
> some text TOKEN some more text
> a lot of text on this line but no token

This is only a partial solution -- if there was a value for each
token, I could do it pretty easily using this find/replace tested
here:
http://tinyurl.com/8j9zh

However, I'm not sure how to re-use the captured value on consecutive
tokens.  Would be good to know. ; If it is possible to do this with a
single query, someone else on this list more capable than I ought to
be able to lend a hand.

A.

--
Remember, no matter where you go, there you are. -Buckaroo Banzai

-------------------------------------------------------------------
Jean-Claude Terrier, trad. a.      SOGETRA - Traducteurs & Conseillers
jterriersogetra.com           ;      translatsogetra.com
Téléphone/télécopie : (514) 842-3888  
8090, ave San Francisco BROSSARD Qc Canada J4X 1Y4
-------------------------------------------------------------------

Rgex to insert variable value in text
user name
2006-02-14 23:00:23
Jean-Claude Terrier <jterriersogetra.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
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )