in reply to Re: Perl store as variables regex matches for use outside of loop.
in thread Perl store as variables regex matches for use outside of loop.

Regarding matching numbers ... I have recently gone back to using the old-school

/[0-9]+/

because of (in Using character classes)

Since the introduction of Unicode, unless the //a modifier is in effec +t, these character classes match more than just a few characters in t +he ASCII range. \d matches a digit, not just [0-9] but also digits from non-roman scri +pts

There are a lot of characters flying around out there. But some stuff still needs to be limited to ASCII -- for example book ref numbers, even if your book titles may have non-Roman characters; or a primary key from a database table in a multilingual CMS ...

So if you want to make sure you are matching only Roman script digits, and you need to work on perls older than 5.14, you should probably use the old [0-9]. If you have a new perl, you can do:

/\d+/a

which will limit the match to ASCII characters ...

Remember: Ne dederis in spiritu molere illegitimi!

Replies are listed 'Best First'.
Re^3: Perl store as variables regex matches for use outside of loop.
by Laurent_R (Canon) on Jul 12, 2015 at 17:50 UTC
    Yes, 1nickt, you're absolutely right, we have to be quite careful about these things nowadays. I am not dealing too often with Unicode or UTF8 data, and mostly with pure ASCII or sometimes with an extended ASCII Latin character set, so that I don't always think about the possibility of character classes matching more than I usually expect. Thank you for reminding.

    Having said that, I was not presenting production code, not even a complete working program, but just trying to identify some of the errors in the OP code and show some ways to correct them.