in reply to chomp and regexp

I understood [chomp] to equivalent to s/ +$//; when used as above with no new lines.

No, as per its docs:

... removes any trailing string that corresponds to the current value of $/...

So normally that's just "\n". Update: The idiomatic way to trim other whitespace from strings in Perl is in fact with regexen, e.g. s/^\s+|\s+$//g. /Update

s/[^az09 _\-\+\.]//g

You appear to be missing the dash in the two ranges: s/[^a-z0-9 _\-\+\.]//g

How should I go about properly working out how to construct a regexp to do what I want?

Though it doesn't support all the advanced features of Perl, you could use https://regex101.com. When developing regexen, it's always best to have lots of test cases, and not only positive (what you want to match) but also negative (what you don't want to match). The site's "unit test" feature is very useful for that. (Of course there's also my WebPerl Regex Tester.)

Replies are listed 'Best First'.
Re^2: chomp and regexp
by ikegami (Patriarch) on Sep 14, 2023 at 17:43 UTC

    The idiomatic way to trim other whitespace from strings in Perl is in fact with regexen

    You can now use

    use builtin qw( trim );

    However, it's currently experimental.

Re^2: chomp and regexp
by Bod (Parson) on Sep 14, 2023 at 15:02 UTC
    You appear to be missing the dash in the two ranges: s/[^a-z0-9 _\-\+\.]//g

    Oh...it's good to know that I wasn't too far out!
    Thank you.