How to insert flag in regular expression?

AkashiDom

Active member
Is macrodroid regular expression support flag? How do I insert it?
Flag are like g, i and m which mostly available at the end of regular expression like /^#.*/gm.
Which gm is a flag

I didn't know if I could put / at start and end of regular expression in macrodroid because last time I tested it, it worked without / so now I'm wondering,

How do I insert flag? Do / can be putted at front and end of regular expression in macrdroid?​

 

Yogi

Member

Regular Expressions

A regular expression (also “regexp”, or just “reg”) consists of a pattern and optional flags.
There are two syntaxes that can be used to create a regular expression object.

The “long” syntax:

regexp = new RegExp("pattern", "flags");


And the “short” one, using slashes "/":

regexp = /pattern/; // no flags
regexp = /pattern/gmi; // with flags g,m and i (to be covered soon)
Slashes /.../ tell JavaScript that we are creating a regular expression. They play the same role as quotes for strings.

In both cases regexp becomes an instance of the built-in RegExp class.

The main difference between these two syntaxes is that pattern using slashes /.../ does not allow for expressions to be inserted (like string template literals with ${...}). They are fully static.

Slashes are used when we know the regular expression at the code writing time – and that’s the most common situation. While new RegExp is more often used when we need to create a regexp “on the fly” from a dynamically generated string. For instance:

this should answer your question, if you use a variable and not a fixed string - as far as I understand you do - you have to use the
"long" syntax and put for the flags e.g.
JavaScript:
"i"
and as far as I see the MD variable has to be put in the regex like
JavaScript:
new RegExp(/{lv=username}/,"i")
(used the sample variable from your other post)
 

Endercraft

Moderator (& bug finder :D)
this should answer your question, if you use a variable and not a fixed string - as far as I understand you do - you have to use the
"long" syntax and put for the flags e.g.
JavaScript:
"i"
and as far as I see the MD variable has to be put in the regex like
JavaScript:
new RegExp(/{lv=username}/,"i")
(used the sample variable from your other post)
I was going to post a reply right as you did!
 

AkashiDom

Active member
Thanks! For
this should answer your question, if you use a variable and not a fixed string - as far as I understand you do - you have to use the
"long" syntax and put for the flags e.g.
JavaScript:
"i"
and as far as I see the MD variable has to be put in the regex like
JavaScript:
new RegExp(/{lv=username}/,"i")
(used the sample variable from your other post)
This.

But I have a question, what about stuff that not JavaScript? Like the compare value screen.
 

Endercraft

Moderator (& bug finder :D)
There is a way, if you search the forum the answer is somewhere (something like you can specify flags directly in the regex).
 

Yogi

Member
Thanks! For

This.

But I have a question, what about stuff that not JavaScript? Like the compare value screen.
Just check "Enable regular expression matching"
and use for the flags the syntax
JavaScript:
(?i)UserName.*
should match USERNAME or username etc.
 
Top