in reply to \s matches newline in regex?

It seems like \s is matching the newline character,
Yes.

Tip #9 from the Basic debugging checklist: YAPE::Regex::Explain

The regular expression: (?-imsx:Hi\s*) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- Hi 'Hi' ---------------------------------------------------------------------- \s* whitespace (\n, \r, \t, \f, and " ") (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
This works for your simple input:
$line =~ s/Hi[^\n]*//;

Replies are listed 'Best First'.
Re^2: \s matches newline in regex?
by Only1KW (Sexton) on Jul 22, 2015 at 16:49 UTC
    So if \s matches more than a space, how do I match just a space? While I agree your suggestion works for my simple example, it won't work for my actual workload.

      You can use [ ], or \x{20} or \U{0020} I guess.

      If you want just a space use just a space! If you want to match everything except some specific white space characters use a negated character class with \S and the other white space characters you want to keep:

      s/Hi[^\S\n\r\f]+//g

      for example.

      Premature optimization is the root of all job security