Skip to main content

App Automation: Regular Expression [REGEX]


Regular Expression or REGEX is widely used to make searching/find characters in a string.

When you run a test on LambdaTest using a specific device, there may be scenarios, in which the particular device that you selected isn’t available. In these scenarios, REGEX will help you widen the search request for devices to run the test on.

To quote an example, consider you want to run the test on an iPhone. It doesn’t matter which one, but it’s got to be an iPhone. In these cases, we can use REGEX to specify exactly that. You’ll now be allotted any iPhone that’s available which widens the search of devices considerably.

REGEX CHARACTERSDESCRIPTIONEXAMPLE
.*The characters .* are used to include all the devices that match the string passed.

In the example given:
You’ll be allocated any device from the Inventory that’s an iPhone or a Pixel device respectively.
"iPhone.*"
"Pixel.*"
,This character , is used to include more combinations of different devices.

In the example given:
1. We have added 2 regex in the example .* and , to show that using both in combination, we’ll fetch any device from the Inventory that contains the string Pixel, Nexus, Galaxy.
2. You’ll be allocated any available Pixel or Nexus or Galaxy device.
"Pixel.*,Nexus.*,Galaxy.*"
[]The [] is used to include special characters like + in the search. Not using the [] will prevent the special characters from being included in the search.

In the example given:
1. You’ll be allocated any Galaxy Note 10+.
2. Incase you send "Galaxy Note 10+" then, you’ll get Galaxy Note 10.
"Galaxy Note 10[+]"
[]The [] is used to include a range of devices in the combination mentioned using a single character only.

In the example given:
Fetching any device available from Pixel 3, Pixel 3a, Pixel 4, Pixel 5, Pixel 6, Pixel 6 Pro, etc.
“Pixel [3456]"
$The $ character indicates the end of a string.

In the example given:
1. Allocating only Pixel 6 device & will neglect the Pixel 6 Pro devices.
2. Allocating only the Pixel 3 device while neglecting Pixel 3a, Pixel 3 XL etc.
“Pixel 6$"
"Pixel [36]$"
^The ^ is used to negate a character from the search.

In the example given:
The first part of this regex .* includes all the OnePlus devices, whereas the second part [^8] neglects OnePlus 8, OnePlus 8 Pro devices as it contains the character 8, which is negated.
“OnePlus.* [^8]"

Got any questions?
Please reach out at our 24x7 Chat Support or you could also mail us at [email protected].

TestU Conf