NOT BUG : Macrodroid v5.41.5 pro - Text Manipulation, extract text, regex negative lookahead, fails

Hello, ended up going down a regex rabbit hole a couple weeks ago.

And have since done my usual tidying up of Macrodroid, deleting the related regex test macro.

This is not a priority for me.

However, I did find some notes from my testing.

So folks can recreate if desired if determined can be fixed.

grep -P regex succeeds.

And, Macrodroid javascript succeeds.

regex101 succeeds.

Below is the data for a simple recreate if desired.

Text manipulation, Extract Text
^(?!http|https).+

smtp://xyz.mail
ftp://file.txt


javascript
var jetpack_out = "notinitjs";
const s = 'http://abc.com\nsmtp://xyz.com\nhttp://abc.com\nhttps://mno.org\nftp://file.txt' ;
const pattern = /^(?!http|https).+/gm;
const match = s.match(pattern);
console.log(match, '\n`, new Date().toISOString());




reregex101.jpg
 

Endercraft

Moderator (& bug finder :D)
By default other tools (like regex101.com) use the m flag (you can see m is included in /gm) which means ^ and $ match the beginning and end of each line and not beginning and end of the whole string. MacroDroid doesn't use it by default.
Modify your regex like so and use full match :
(?m)^(?!https?).+(\n|)
Explanation:
  • (?m) means use the m modifier.
  • (\n|) matches a newline or nothing. It's not strictly necessary but not using it will make your results not being separated by a newline.
  • Instead of seeing if the lookahead is http or https you are looking it it is http and optionally https (s? means s 0 or 1 time).
 
Last edited:
Top