String being reviewed: 2018-01-07â15-09-53-Name of_file-.jpg
Regular expression used in KM: [\p{L}\s._0-9-]+
Output variable after regex application in KM: 2018-01-07â15-23-34-Name of_file-
Expected output: 2018-01-07â15-09-53-Name of_file-.jpg
And this is what happens at https://regex101.com/r/CkdY9t/1), the is removed and â.jpgâ is part of the output.
I have not been able to figure out why KM regex application leaves out the .jpg.
It is only supposed to remove the
Why am I doing this: I am trying to remove any characters that cannot be part of a file name on Mac/
I am using the "Get Substring of Variable" action in KM and therefore chose PCRE on regex101.
Based on this Wiki link for Regex in KM
"Keyboard Maestro uses ICU Regular Expressions (aka RegEx or RegExp) which is very similar to PCRE (Perl Compatible Regular Expressions), and you can read their documentation by choosing ICU Regular Expression Reference from the Help menu in Keyboard Maestro."
Am now going to try with javascript option at regex101.
As you know, Emoji are tricky multi-byte unicode things - you may need to search for some StackOverflow discussion of matching them, and perhaps use their codes rather than glyphs in your regex expressions.
So it seems that KM macro only returns the first match, even though the wiki page says -
All searches are global in Keyboard Maestro.
In my application, the portion after any special character is missed. I simplified the regex.
.jpg which follows after the is the second match, but is missed.
I think you might find it easier, and more effective, to search for any character that does NOT match your desired characters. This would be the RegEx: [^\p{L}\s._0-9\-]
Then just do a simple Search and Replace, which will replace ALL matches.
Here's an example macro:
Example Results
##Macro Library Remove Unwanted Characters from String using RegEx
####DOWNLOAD:
<a class="attachment" href="/uploads/default/original/3X/0/a/0a31c5c468ac932fced90545b6d68f2907abee3a.kmmacros">Remove Unwanted Characters from String using RegEx.kmmacros</a> (2.9 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**
---
<img src="/uploads/default/original/3X/5/0/508e0ff84417148a499d3892b266d5fd18879ebb.png" width="560" height="719">