Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Perl Monk, Perl Meditation
 
PerlMonks  

Re: remove specific data from a line

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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 10: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
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.