in reply to Re^2: Reg exp questions
in thread Reg exp questions

Show your exact input strings, and your expected output strings. http://sscce.org

Replies are listed 'Best First'.
Re^4: Reg exp questions
by carolw (Sexton) on Nov 07, 2014 at 19:38 UTC

    my $str = 'dfsldjf(djfls)jfslfk kfds\nfjsldf';

    output: dfsldjf_djfls_jfslfk_kfds fjsldf

      Did you really mean to include a newline character (single quotes prevent interpolation)?
      use warnings; use strict; my $str = 'dfsldjf(djfls)jfslfk kfds\nfjsldf'; $str =~ s/[\s()]/_/g; $str =~ s/\\n/ /g; print "$str\n"; __END__ dfsldjf_djfls_jfslfk_kfds fjsldf

        well I have a file a lines and there is \n between lines. In order to send an example of what I have in one string, I included \n in the string. Otherwise, it's like

        HeadeRdfsldjf(djfls)jfslfk kfd

        lfjslfjsflk

        dkflskfs

        HeadeRRdfsldjf(djfls)jfslfk kfd

        lfjslfjsflk

        dkflskfs

        in the header line, ()\s should be replaced by _, \n at the end should be replaced by \s, on the following lines without Header, \n should be removed except the last one so that it won't be concatenated with the next header line:

        HeadeRdfsldjf_djfls_jfslfk_kfd lfjslfjsflkdkflskfs

        HeadeRdfsldjf_djfls_jfslfk_kfd lfjslfjsflkdkflskfs

        =~ s/\\n/ /g; doesn't work for me. I don't get space instead of \n.

        So finally, $str =~ s/\n/ /g; removes \n. Does it remove EOF, too? If so, how to avoid?