RegEx Beginning/End-of-Line Anchors Not Working?

I concede your point and wouldn’t want to restrict usage of regexps anywhere.

But maybe we could distinguish between actions that expect a regexp get the popup and those that accept one don’t (remaining the same as now).

Power users won’t be frustrated and people learning regexp will be helped where it’s most needed.

Interesting idea! And one that seems quite doable. Here's a quick proof-of-concept to get us started:

Regex Flags.kmmacros (5.3 KB)

As far as I'm aware there's no way to turn the global flag off, and the x whitespace/comment flag didn't seem particularly useful given the way KM handles regex (though that could also just be because I've yet to find a use for it), so these should (hopefully!) be enough to cover the majority of KM user needs (especially since, again, this is just a proof of concept to get us started).

1 Like

Great start, @gglick! :+1:

Just to test/reinforce my memory about showing one value, but storing a different value, in the Prompt for User Input, I took a different approach. For example:

  • Variable: Local__Multi_Line
  • Default Value: __No|m__Yes (?m)

The first value, before the "__", is the value to be stored.
The value after the "__" is the one that is displayed to the user.
Just for clarity, the vertical bar "|" used above has nothing to do with this. It just provides the choices of the popup list that will be shown.

I didn't know if using nothing for the stored value would work, but it turns it does. So the __No, for example, returns the empty string "" if the user selects "No".

Some RegEx programmers may object to use of my title of "Dot_Newline" instead of the traditional "Single_Line". But I think it is clearer to the novice user, because seeing both "Multi_Line" and "Single_Line" might seem like a contradiction to some.

Obviously, the user of this macro can change it to be whatever he/she prefers.

I also use all Local variables because I wanted to start with a clean sheet of NO options every time. If you prefer a different default, you can just switch the order of the Default Value in the Prompt, For example, change:
FROM: __No|m__Yes (?m)
TO: m__Yes (?m)|__No


Here's my DRAFT Macro:

### Example Output

<img src="/uploads/default/original/2X/c/c8c3ef8463c83ded88afe5d096d737c5f561f4fe.png" width="539" height="339">

#### With ALL Options Selected:
<img src="/uploads/default/original/2X/0/0e4e0aec23903e48794ee9ba0aea799e51b4f398.png" width="539" height="339">

**Result Pasted**
`(?msi)`

###MACRO:&nbsp;&nbsp;&nbsp;Prompt User for RegEx Flag Options and Paste

~~~ VER: 0.1&nbsp;&nbsp;&nbsp;&nbsp;2017-10-19 ~~~

####DOWNLOAD:
<a class="attachment" href="/uploads/default/original/2X/b/b19289980ce3ac4beb7a58b486590c6fa4b9c51a.kmmacros">Prompt User for RegEx Flag Options and Paste.kmmacros</a> (9.9 KB)
**Notes: This Macro was uploaded:**
  1. In a DISABLED state. You must enable before it can be triggered.
  2. With a Typed String Trigger.

---


<img src="/uploads/default/original/2X/a/adcf53ba4ad11216d839adb47cd708ceeb39d744.png" width="531" height="1509">

### To Those New to RegEx

Please give the above macros by @gglick and myself a try, and give us some feedback on how it works for you, and what changes/improvements you'd like to see, to make it user-friendly for you.
1 Like

I like that Help option. Here's a checkbox version:

Keyboard Maestro 8.0.3 “Regexp Options” Macro

Regexp Options.kmmacros (11 KB)

1 Like

Another good choice. I like your name of "Ignore Case" better than "Insensitive". I'm going to change my macro to use that.