Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Regexp to truncate

Thread Tools

Regexp to truncate

Yannick Turgeon
Posts: n/a
Hello all,

I just started to use perl and I'm having a Regexp question:

Say we've got a file with this in it:
---- Beginning of file after this line --------
My list
A: cat
B: dog
C: horse
A: cow
C: bird
---- End of file before this line --------

What I'd like to do is to truncate everything before the animal
associated with the FIRST occurence of a label. Here with the label "A:"
I'd like to truncate everything before "cat" (and not before "cow")

# This truncate the string before "cow"
$myFileString =~ s/ ^ .* A:\ //sx;

Anybody can help?

One more thing. I use the "s" option but I don't undestand it quite well.
On the net, I've found the following:
"This option treats the string as a single line."
in which situation this could be a problem or something we don't want?


Reply With Quote
Yannick Turgeon
Posts: n/a
Answered on another list.
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
new RegExp().test() or just RegExp().test() Matěj Cepl Javascript 3 11-24-2009 02:41 PM
[regexp] How to convert string "/regexp/i" to /regexp/i - ? Joao Silva Ruby 16 08-21-2009 05:52 PM
Ruby 1.9 - ArgumentError: incompatible encoding regexp match(US-ASCII regexp with ISO-2022-JP string) Mikel Lindsaar Ruby 0 03-31-2008 10:27 AM
Programmatically turning a Regexp into an anchored Regexp Greg Hurrell Ruby 4 02-14-2007 06:56 PM
RegExp.exec() returns null when there is a match - a JavaScript RegExp bug? Uldis Bojars Javascript 2 12-17-2006 09:59 PM