Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: remove specific data from a line

by idle (Friar)
on Feb 02, 2006 at 15:26 UTC ( [id://527345]=note: print w/replies, xml ) Need Help??


in reply to remove specific data from a line

So you wanna remove the string if it start with myword? Try this:
if $line =~ /^myword.*$/ { $line =~ s/$&//g }
Updated. Oh I see you need to remove the line until the last option. Heres the code:
if $line =~ /(^myword.*option\d+\s+).*$/ { $line =~ s/$1//g }

Replies are listed 'Best First'.
Re^2: remove specific data from a line
by Anonymous Monk on Feb 02, 2006 at 15:36 UTC
    I not explain too good sorry. Let me try eloborate. String could look like this
    abc123 qwerty,asdfg,zxcvb yuio jklh
    or like this
    abc987 qwerty yuio jklh
    or this
    abcefgh qwerty, asdfg yuio jklh
    So I want to end up with same string from all examples above. It should end up like this
    yuio jklh
    Hope this make it bit clearer, sorry for confuse my english not so good
      Given those examples, there might be a few ways to do this -- either try to match from the start of the string:
      s/abc\w+\s+\w+(?:, *\w+)\s+//; # match and remove unwanted initial co +ntent
      or else just look for what you want to keep at the end:
      s/.*\s(\w+\s+\w+)$/$1/; # match desired end content and remove everyt +hing before it
      And of course, if you know in advance how those last two tokens are spelled, you could even use rindex() and substr():
      $_ = substr( $_, rindex( $_, 'yuio jklh' ));
        Thank for answer but not quite what I look for. This  s/abc\w+\s+\w+(?:, *\w+)\s+//; only work correct on last line of my example.
        I'm not able to use second or third option you supply because I do not know what end of line hold only what beginning of line look like. See my reponse to Roy Johnson. Thanks

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://527345]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-20 05:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found