Create Condition filter incoming_number with wildcards

Post your questions and help other users.

Moderator: Martin

Post Reply
toonwolf
Posts: 3
Joined: 13 Feb 2014 06:27

Create Condition filter incoming_number with wildcards

Post by toonwolf » 13 Feb 2014 08:12

My goal is to create a flow that will reply with an sms when in a meeting. However if the incoming_number is starting with 715* and 675* (landline) then I would like the flow to stop. I tried to experiment with Expression "incoming_number=="715*", but that is not working. Can someone please help me with the correct syntax?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Create Condition filter incoming_number with wildcards

Post by Martin » 13 Feb 2014 17:40

incoming_number=="715*" tests whether the number is exactly 715* (wildcards like * is not supported in strings like this).

You could use following script to test if a number starts with a prefix:

Code: Select all

startsWith(incoming_number, "715");
or using regular expressions:

Code: Select all

matches(incoming_number, "715.*");

toonwolf
Posts: 3
Joined: 13 Feb 2014 06:27

Re: Create Condition filter incoming_number with wildcards

Post by toonwolf » 13 Feb 2014 18:45

Thank you for your reply. Is it possible to build an expression with more than one number?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Create Condition filter incoming_number with wildcards

Post by Martin » 13 Feb 2014 19:31

You can combine multiple expressions with an or-operator, either || or OR (both operators have the same meaning):

Code: Select all

startsWith(incoming_number, "715") || startsWith(incoming_number, "675");
respectively:

Code: Select all

startsWith(incoming_number, "715") OR startsWith(incoming_number, "675");
or with regular expressions:

Code: Select all

matches(incoming_number, "(715|675).*");

toonwolf
Posts: 3
Joined: 13 Feb 2014 06:27

Re: Create Condition filter incoming_number with wildcards

Post by toonwolf » 14 Feb 2014 05:56

Thank you so much for your help. Tested and works like expected!

tphg
Posts: 57
Joined: 17 Apr 2017 05:31

Re: Create Condition filter incoming_number with wildcards

Post by tphg » 30 Dec 2017 05:06

Martin wrote:You can combine multiple expressions with an or-operator, either || or OR (both operators have the same meaning):

Code: Select all

startsWith(incoming_number, "715") || startsWith(incoming_number, "675");
respectively:

Code: Select all

startsWith(incoming_number, "715") OR startsWith(incoming_number, "675");
or with regular expressions:

Code: Select all

matches(incoming_number, "(715|675).*");
Thanks for your useful instruction.
But it failed to work when I add in area codes, e.g.

Code: Select all

matches(incoming_number, "(+22|+23).*");
Please advise how the correct expression syntax is in this case.
Thanks in advance.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Create Condition filter incoming_number with wildcards

Post by Desmanto » 30 Dec 2017 06:14

tphg wrote: Thanks for your useful instruction.
But it failed to work when I add in area codes, e.g.

Code: Select all

matches(incoming_number, "(+22|+23).*");
Please advise how the correct expression syntax is in this case.
Thanks in advance.
+ has special meaning in regex, it must be escaped using backslash. Since automagic backslash is a special character too, it must be escaped too with another backslash. So it should be.

Code: Select all

matches(incoming_number, "(\\+22|\\+23).*");
You can always try the regex using the built-in regex tester. When you put the regex without the backslash, it will show you syntax error. Anytime you deal with symbol and you encounter the syntax error, most likely you need to escape it using backslash.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

tphg
Posts: 57
Joined: 17 Apr 2017 05:31

Re: Create Condition filter incoming_number with wildcards

Post by tphg » 30 Dec 2017 08:09

Oh, it works like a charm.
Thank you @desmanto, and wishing you a Happy New Year!
-----------------------------------
P/S: Please have a look on my recent post on "SMS blocker based on keyword" at your convenience. I think you could help me.

Post Reply