Regexp to truncate

Y

Yannick Turgeon

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?

TIA

Yannick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top