Re: Using regular expressions to insert tags
[email protected] ("Brad Baxter") Tue, 20 Jun 2006 10:46:04 -0400
| Newsgroups | perl.scripts |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_133321_29111543.1150814764147 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 6/20/06, Sriram Rajagopalan <[email protected]> wrote: > > Hello, > > I have a text file in a columnar format. There are seven entries in a row, > separated by tabs. > > eg. > > 1 23 555 34 Corporation Index Sediment > > This has to be tagged as: > > > <no>1</no><code>23</code><set>555</set><id>34</id><status>Corporation</status><value>Index</value><type>Sediment</type> > > I have stored the file contents to $_ and I am using the regex > > > $_=~s/([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t/<no>$1<\/no><code>$2<\/code><set>$3<\/set><id>$4<\/id><status>$5<\/status><value>$6<\/value><type>$7<\/type>/g; > > I am not able to get the text tagged. Can anyone help me out to get my > desired codes? > Your regex is expecting a tab after Sediment. Is there one? -- Brad ------=_Part_133321_29111543.1150814764147 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 6/20/06, <b class="gmail_sendername">Sriram Rajagopalan</b> <<a href="mailto:[email protected]">[email protected]</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> <div> <div> <p align="left"><font face="Verdana" size="2">Hello,</font></p> <p align="left"><font face="Verdana" size="2">I have a text file in a columnar format. There are seven entries in a row, separated by tabs.</font></p> <p align="left"><font face="Verdana" size="2">eg.</font></p> <p align="left"><font face="Verdana" size="2">1 23 555 34 Corporation Index Sediment</font></p> <p align="left"><font face="Verdana" size="2">This has to be tagged as:</font></p> <p align="left"><font face="Verdana" size="2"><no>1</no><code>23</code><set>555</set><id>34</id><status>Corporation</status><value>Index</value><type>Sediment</type> </font></p> <p align="left"><font face="Verdana" size="2">I have stored the file contents to $_ and I am using the regex</font></p> <p align="left"><font face="Verdana" size="2">$_=~s/([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t/<no>$1<\/no><code>$2<\/code><set>$3<\/set><id>$4<\/id><status>$5<\/status><value>$6<\/value><type>$7<\/type>/g; </font></p> <p align="left"><font face="Verdana" size="2">I am not able to get the text tagged. Can anyone help me out to get my desired codes?</font></p></div></div></blockquote></div>Your regex is expecting a tab after Sediment. Is there one? <br><br>-- <br>Brad<br> ------=_Part_133321_29111543.1150814764147--