Skip to content

Custom Regular expression Reference

Choiman1559 edited this page May 15, 2022 · 3 revisions

Overview

Last Update: 05/15/2022 23:39 (KST)

This document is a reference for the Regex of the Regex Customizing function within the Noti Sender, And The contents of this document are subject to change without notice depending on the development situation.

This script is basically based on JavaScript grammar, and the script the user enters is finally executed by the JavaScript Runtime on Android Webview.

Data Types

String

A string is zero or more characters written inside quotes.

example:
'Hello! This is String!'

You can also use two quotes:
"Hello! This is String!"

Boolean

A Boolean represents one of two values: true or false.

example:
(true) -> returns always true
(false) -> returns always false

Function

There is only one function in this script:

boolean matchExpr(String Regex, String StringToTest)

String Regex : Regular expression to check string
String StringToTest : Some string to check

return value : boolean -> Returns true if the regular expression matches the string, false otherwise.

Operators

An operator performs some operation on single or multiple operands (data value) and produces a result.

Operator Name Description
&& And It checks whether two operands are not.
|| Or It checks whether any one of the two operands is not.
== Equals Compares the equality of two operands.
!= Non-Equals Compares inequality of two operands.
! Not It reverses the boolean result of the operand (or condition).
? : Ternary The ternary operator starts with conditional expression followed by the ? operator. The second part (after ? and before :) will be executed if the condition turns out to be true. Suppose, the condition returns false, then the third part (after :) will be executed.

Prefix Data set

Information about alarm data received from other devices.
WARNING: You must enclose it in quotation marks like a normal string. (example: '$APP_NAME')

Expression Name Description
$TITLE Title of Notification The subject of the sent notification data.
$CONTENT Content of Notification The content of the sent notification data.
$PACKAGE_NAME Package name The package name of the app that sent the notification.
$APP_NAME App name The name of the app that sent the notification.
$DEVICE_NAME Device name The name of the device that sent the notification. It usually takes the form of "manufacturer" + "device name", and you can find the name of this device in the "Pair Devices" function.
$DATE Date The time the notification was sent. It is expressed in the form of "yyyy-MM-dd HH:mm:ss".

Examples

1. matchExpr('$TITLE', 'Hello*') || matchExpr('$DEVICE_NAME', 'Pixel*')
True if the subject of the received notification data contains "Hello" or the device name contains "Pixel", false otherwise

2 '$APP_NAME' == "WhatsApp"
True if the name of the app is "WhatsApp", false otherwise

3 matchExpr('$CONTENT', matchExpr('$CONTENT', '^.*-.*$') ? '^[1-9]\d{2}-\d{3}-\d{4}' : '^[1-9]\d{2}\s\d{3}\s\d{4}')

We can decompose this into two processes:

If $CONTENT contains a "-" character:
Checking a regular expression of the form "###-####-####"

Otherwise :
Checking for regular expressions of the form "### #### ####"

Clone this wiki locally