Why is a Regular Expression Working in Atom but Not in KM?

Hey All,

Hopefully a simple question.

My regex works in Atom and Regex101.com but not in KM. Any idea why?

Trying to match second time in first line (in example, 10:30 AM.)

Source text:

9 AM-10:30 AM  1
12 PM-12:30 PM  2

Regex

(?<=-).*(?=..1$)

image

Thank you!

1 Like

You've helpfully given one or more source texts [not quite clear], but you've left "works" undefined.

(You haven't told us what substring(s ?) you are hoping to match)

Oh right on. I'm hoping to match the end time in the first line. So in this example, 10:30 AM.

9 AM-10:30 AM 1
12 PM-12:30 PM 2

Or alternatively,

3 PM-4:00 PM 1
12 PM-12:30 PM 2

I'm building a macro that shows me the open spots in my schedule. The quite old medical records system does not show open appointments but only scheduled appointments. So I am extracting the times and then calculating open time slots from that.

This regex covers a few more cases (like the third item) than your test suite:

ss-682

It is.

The issue is that Keyboard Maestro does not turn on multi-line by default, so your input is seen as a single string and not lines.

Without mult-line enabled $ represents the end of the string and not the end of a line, so your pattern fails.

Here's the fix.

(?m)(?<=-).*(?=..1$)

Download: RegEx Test ⇢ Search .kmmacros (3.7 KB)
Keyboard Maestro Export

Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 10.14.6
  • Keyboard Maestro v10.2

3 Likes

Oops, seems I got the specifications wrong. Here's a revision of my approach, whose regex I think is a bit easier to read (if less magical):

Time Free.kmmacros (2.2 KB)

Keyboard Maestro Export

1 Like

Thank you all!!! Works like a charm!

J