in reply to How to trim a line from leading and trailing blanks without using regex or non-standard modules

> which clearly is an abuse of regex.

Why is it an abuse of regex?

Problem is that \s is a meta character for any white-space not only blank " " , but only usable inside regex.°

So if you want the exact same semantic, it'll become far more complicated than this regex.

But better define your own trim() using a regex inside.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

°) compare Re^3: How to trim a line from leading and trailing blanks without using regex or non-standard modules

  • Comment on Re: How to trim a line from leading and trailing blanks without using regex or non-standard modules
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: How to trim a line from leading and trailing blanks without using regex or non-standard modules
by likbez (Sexton) on Aug 14, 2020 at 19:39 UTC
    So if you want the exact same semantic, it'll become far more complicated than this regex.

    I agree. That's a good point. Thank you !

    In other words it is not easy to design a good trim function without regex, but it is possible to design one that used regex, but treating the single quoted string as a special case

    For example

    trim(' ',$line)
    vs
    trim(/\s/.$line)
    BTW this is impossible in Python which implements regex via library, unless you add a new lexical type to the Language (regex string instead of raw string that is used).