I need to grep the following:
my $string = "Thanks for contacting support. Your ticket number: 123. All the best!"
or
my $string = "Thanks for contacting support. Your ticket #: 123. All the best!”
How can I grep 123 into variable $ticket_no with PERL?
I think the regexp should be something like this ticket[ \t]+(number|#)?[: \t]+([0-9]+)
Is it correct?
Yes, that regex would work. You could use it like this:
Note that you’ll want to handle, somehow, the case that the regular expression didn’t match, since in that case,
$ticket_nowill be undefined.