[Chicago-talk] Can anyone help with a regex?

Andy Bach Andy_Bach at wiwb.uscourts.gov
Wed Apr 3 11:31:02 PDT 2024


my $line = "ACCT/ID Number(s): 1334356";
my $d = "ACCT/ID Number(s):";

The parens in $d are metachars, so they don't match actual parens, but are capture markers.  You could use "." to match one char
my $d = "ACCT/ID Number.s.:";

gets
Found ACCT/ID Number(s): in line

but would also match that sequence with other chars besides parens. You could escape the parens - easier if you then use single quotes, so the escapes won't "go away"
my $d = 'ACCT/ID Number\(s\):';

gets
Found ACCT/ID Number\(s\): in line

so, the best, as mentioned, is \Q ...\E to escape any metachars between those markers in the match
if ($line =~ /\b\Q$d\E(\s|$)/) {

gets
Found ACCT/ID Number(s): in line
________________________________
From: Chicago-talk <chicago-talk-bounces+andy_bach=wiwb.uscourts.gov at pm.org> on behalf of Richard Reina <richard at rushlogistics.com>
Sent: Wednesday, April 3, 2024 12:33 PM
To: chicago-talk at pm.org <chicago-talk at pm.org>
Subject: [Chicago-talk] Can anyone help with a regex?

CAUTION - EXTERNAL:


I want to be able to find the sting 'ACCT/ID Number(s):'

Here's what I've tried so far.


my $line = "ACCT/ID Number(s): 1334356";
my $d = "ACCT/ID Number(s):";


if ($line =~ /\b$d(\s|$)/) {

    print "Found $d in line\n";

}


_______________________________________________
Chicago-talk mailing list
Chicago-talk at pm.org
https://mail.pm.org/mailman/listinfo/chicago-talk
CAUTION - EXTERNAL EMAIL: This email originated outside the Judiciary. Exercise caution when opening attachments or clicking on links.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20240403/0522ce67/attachment-0001.html>


More information about the Chicago-talk mailing list