Re: [Boston.pm] more specific regex error messages?
"Morse, Richard E.,MGH via Boston-pm" <[email protected]> Fri, 25 Feb 2022 18:24:10 +0000
| Newsgroups | gmane.comp.lang.perl.perl-mongers.boston |
|---|---|
| Message-ID | <MN2PR04MB640034AF400DDE7DC3E19AF0E73E9@MN2PR04MB6400.namprd04.prod.outlook.com> |
Maybe something like "use re 'debug'"? https://perldoc.perl.org/re#'debug'-mode There's a bunch of options, and it seems to be present, at least in some form, as early as Perl 5.10? Ricky ________________________________________ From: Boston-pm <boston-pm-bounces+remorse=mgh.harvard.edu-aE07yma9hCw@public.gmane.org> on behalf of email-2Ro/Dj86MvDSUeElwK9/[email protected] <email-2Ro/Dj86MvDSUeElwK9/[email protected]> Sent: Friday, February 25, 2022 1:19 PM To: [email protected] Subject: [Boston.pm] more specific regex error messages? External Email - Use Caution I have a rather complex regex that I'm throwing text at. if($str=~m/\Athing1\:thing2\,thing3\@(\w+)\?(\d+)\Z/){ # process str } else { die "bad str 'str' "; } Is there a way to get better built in reporting with regexps? with the above, if the string doesn't match, I get "bad input". What I'd rather get is something like "expecting \:thing2" if need be, I'll break it into a series of nested ifs. but that would be exceedingly ugly. The pattern does not require backtracking. I've already checked that I'm in a certain location and only one kind of input is expected. and again, I can't load external modules at work. suggestions? Greg _______________________________________________ Boston-pm mailing list [email protected] https://secure-web.cisco.com/1zBy9_BqbfQnntf_x4Qgy8mfHyQaN3gK1FCYKK7rJdR-NaPaore3cOEpItzbBEmpOZon9iCVy4yyPfhRQo9PS4Rpyx3xzWpI1sq5Rj-crQoOfa-JnDr7Yk_p0Q45uIOztjqhwH1RlzjPPxlEFvjP041-80anAdLmINmOPiZvXP07xQq8WIjYYNbe0D4nVOOSLuCvUrikt1Iain4rOdWw0Z88U2exPvx777acH7j65KzWfQOU1Yo5Na6gz_fSwQh5xZNCuAFNRNg_rdwSDEanxwgP1aDNIJv62KeQvQbSoeDmCnB2_DjzZjCVXEs_LLQTeBT-weqfKqxuTwgcnVCty3A/https%3A%2F%2Fmail.pm.org%2Fmailman%2Flistinfo%2Fboston-pm