in reply to Regex check

Deciphering your optical illusion... er, regular expression is a job for YAPE::Regex::Explain:
use warnings; use strict; use YAPE::Regex::Explain; my $re = '[\w().-]*\(?([\w.-])?\)?\s*->\s$'; print YAPE::Regex::Explain->new($re)->explain(); __END__
The regular expression: (?-imsx:[\w().-]*\(?([\w.-])?\)?\s*->\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): ---------------------------------------------------------------------- [\w().-]* any character of: word characters (a-z, A- Z, 0-9, _), '(', ')', '.', '-' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- \(? '(' (optional (matching the most amount possible)) ---------------------------------------------------------------------- ( group and capture to \1 (optional (matching the most amount possible)): ---------------------------------------------------------------------- [\w.-] any character of: word characters (a-z, A-Z, 0-9, _), '.', '-' ---------------------------------------------------------------------- )? end of \1 (NOTE: because you're using a quantifier on this capture, only the LAST repetition of the captured pattern will be stored in \1) ---------------------------------------------------------------------- \)? ')' (optional (matching the most amount possible)) ---------------------------------------------------------------------- \s* whitespace (\n, \r, \t, \f, and " ") (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- -> '->' ---------------------------------------------------------------------- \s whitespace (\n, \r, \t, \f, and " ") ---------------------------------------------------------------------- $ before an optional \n, and the end of the string ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------

Do you really need those capturing parentheses? All the examples in the doc show pretty simple regexes for prompt. Maybe you could try simplifying the regex until it passes some simple case.

is throwing an error
What is the error message?

Replies are listed 'Best First'.
Re^2: Regex check
by spivey49 (Monk) on Aug 15, 2008 at 01:56 UTC

    Ah, thank you! I had forgoten all about YAPE::Regex::Explain.

    The capturing parentheses are needed to pass the expression to a different function.

    What is the error message?

    I'm not entirely sure yet why it's throwing an error. It's an internal error check with Net::Telnet. After much debuging I've determined errmode->mode is being set to die after passing this regex to the prompt method. This causes another function, error(), to exit the script with die, but it doesn't print the error message. I was hoping maybe there was something I was missing with the regex causing the behavior