Regex - help remove a dot after two-factor code

I found a KM macro on the Internet, which copies the two-factor code to the clipboard.

https://tyler.io/a-better-way-to-copy-two-factor-codes-on-macos/

This also works very reliably for me under macOS Big Sur and macOS Monterey.

2022_03_03 Support 2A

03)2FA <091D 220308T094346>.kmmacros (43,9 KB)

Click to show image

03)2FA <091D 220308T094346>

However, I have an advertiser who puts a dot directly after the number code - 765452. - because the number code is the end of a sentence.

Could someone please help me with which input you have to add to the following script to get this dot removed.

sqlite3 "$HOME/Library/Messages/chat.db"   "select text from message order by date desc limit 1" | perl -lpe "s/.* (\d+) .*/\1/g"

Not absolutely sure, but try this instead of the above

perl -lpe "s/.* (\d+).*/\1/g"

so the full script would be:

sqlite3 "$HOME/Library/Messages/chat.db"   "select text from message order by date desc limit 1" | perl -lpe "s/.* (\d+).*/\1/g"
1 Like

Thank you @tiffle for the quick reply :+1:

Your supplement is the right solution. Now it also works if a dot is placed directly after the two-factor code.

2022_03_08_Support_1

1 Like

My interpretation of the regex that you changed to is that it will now "work if any series of characters, not just a dot, appears after the 2FA code." That's because " .* " matches any series of characters. If you just want it to match only a dot, I think you have to replace ".*" with "\."

1 Like

The purpose of the regex is to extract the numeric code - whether followed by a dot or something else - which it does successfully @Sleepy :smiley:

1 Like