From: Sooraj S on 29 Jun 2010 06:42 Hi, My data file : ------------------- // abc def // // abc dser // ---------------------- i want to remove the lines 2 and 4 from the file. check criteria : line should start with // and one or more spaces only as the other characters. i tried this .. if (/^\/\/(\s)*/ ... but it shows entire lines.. How to do it using regular expressions ? Is there any way to find the end of a word using regular expressions ?
From: J�rgen Exner on 29 Jun 2010 06:56 Sooraj S <soorajspadmanabhan(a)gmail.com> wrote: >Hi, > >My data file : >------------------- >// abc def >// >// abc dser >// >---------------------- >i want to remove the lines 2 and 4 from the file. > >check criteria : line should start ^ > with // // >and one or more spaces only + (that is a space character followed by a plus sign) >as the other characters. $ So the whole RE becomes (^// +$) >i tried this .. if (/^\/\/(\s)*/ ... but it shows entire lines.. > >How to do it using regular expressions ? You are plenking. >Is there any way to find the >end of a word using regular expressions ? Sure, from 'perldoc perlre': Assertions Perl defines the following zero-width assertions: \b Match a word boundary But what does that question have to do with your earlier problem statement? jue
From: Steve C on 29 Jun 2010 09:22 J�rgen Exner wrote: > Sooraj S <soorajspadmanabhan(a)gmail.com> wrote: >> How to do it using regular expressions ? > > You are plenking. > Thanks for the new word.
From: J�rgen Exner on 29 Jun 2010 10:30 Steve C <smallpond(a)juno.com> wrote: >J�rgen Exner wrote: >> Sooraj S <soorajspadmanabhan(a)gmail.com> wrote: >>> How to do it using regular expressions ? >> >> You are plenking. > >Thanks for the new word. Nothing new about it: http://en.wikipedia.org/wiki/Plenk jue
From: Justin C on 29 Jun 2010 10:26 On 2010-06-29, Sooraj S <soorajspadmanabhan(a)gmail.com> wrote: > Hi, > > My data file : > ------------------- > // abc def > // > // abc dser > // > ---------------------- > i want to remove the lines 2 and 4 from the file. > > check criteria : line should start with // and one or more spaces only > as the other characters. > > i tried this .. if (/^\/\/(\s)*/ ... but it shows entire lines.. > > How to do it using regular expressions ? Is there any way to find the > end of a word using regular expressions ? I think you want a '+' where you have '*'. '*' means 'any number of times including 0'. '+' means 'at least once'. However, that will still match the lines that you want to keep. You have the '^' to match at the beginning of the string. If only there was something to match the end of the string... Justin. PS Regex word boundary = \b -- Justin C, by the sea.
|
Next
|
Last
Pages: 1 2 Prev: FAQ 5.30 How can I read in a file by paragraphs? Next: FAQ 6.10 What is "/o" really for? |