sandr first occurrence

Post Reply
josmani
Posts: 53
Joined: Tue Jun 03, 2003 3:38 am

sandr first occurrence

Post by josmani »

Hi Guys,

I need some help to sandr the first occurrence of a text in data file.

<$data= "adfafd adsf <tag> text test <tag> <tag>bla bla <component> test text </tag></tag>">

I like to change the first <tag> to <tag2>, how can I achieve this?

Best
User avatar
John
Site Admin
Posts: 2597
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

Re: sandr first occurrence

Post by John »

In your example your tags aren't balanced. Is it just the first open <tag> you are trying to replace, or also change a closing </tag> with possible other <tag></tag> inside?
John Turnbull
Thunderstone Software
josmani
Posts: 53
Joined: Tue Jun 03, 2003 3:38 am

Re: sandr first occurrence

Post by josmani »

I have multiple occurrences of <tag>..</tag> in data but want to only rename the the first occurrence of opening and closing to something else. They are not inside each other.
User avatar
John
Site Admin
Posts: 2597
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

Re: sandr first occurrence

Post by John »

You should be able to use:

<sandr ">>=!<tag>*<tag>=!</tag>+</tag>=" "\2<tag2>\4</tag2>" $data>

The >>= will anchor to the beginning.
John Turnbull
Thunderstone Software
Post Reply