Get your setup working faster. Join our Discord for optimisation tips from elite testers.
Join our Discord
Use regular expression to specify device attributes
Use regular expression to select a device for Appium testing on BrowserStack App Automate. Test on 3000+ devices on our real device cloud.
You can use regular expressions (regex) to select test devices instead of naming specific models and OS versions. Use regex with the deviceName and platformVersion capabilities for the W3C protocol, or with the device and os_version capabilities for the JSON Wire Protocol.
When you pass a regex, BrowserStack allocates the first available device that matches your pattern from the pool of devices on your plan. Widening the match set this way reduces queue time and helps you stay within device-tier limits .
BrowserStack supports the following common regex constructs in the deviceName and platformVersion capabilities:
Regex Value
Description
Examples
.*
. matches any character and * matches 0 or more occurrences of the preceding expression
using iPhone.* in deviceName allocates any iPhone device using .*Pixel.* in deviceName allocates any device with ‘Pixel’ in its name
[]
[] matches any single character in brackets
using [78] in platformVersion allocates any device which is either on OS version 7 or 8
$
$ matches the end of line
using iPhone 12 Pro$ in deviceName allocates an iPhone 12 Pro device but not an iPhone 12 Pro Max device
^
^ matches the beginning of a new line
using ^OnePlus.* in deviceName allocates any OnePlus device
To use this feature on dedicated devices, refer to the Custom Device Lab documentation.
The following code snippet shows how to run a test on any Samsung Galaxy S-series phone with an Android version between 10 and 12:
If you use the BrowserStack SDK as your integration method, specify device attributes with regex in your browserstack.yml file.
Capability
Required/Optional
Description
Sample values
platformName
Required
The mobile operating system to test on.
android or ios
deviceName
Required
The device name, or a regular expression. A matching device is allocated based on your pattern.
Samsung .* allocates any Samsung device. iPhone 1[56]$ allocates an iPhone 15 or iPhone 16.
platformVersion
Optional
The major OS version, or a range of OS versions specified as regex.
1[012] allocates version 10, 11, or 12.
deviceType
Optional
The form factor of the device.
phone or tablet.
Note the following when using the platformVersion capability:
Minor and patch OS versions are not honored in the platformVersion capability.
Escape characters are not supported.
To run tests on a wider set of devices, for example any Samsung Galaxy S-series device, use the following syntax:
```yaml
platforms:
- platformName: android
deviceName: Samsung Galaxy S.*
platformVersion: '1[012]'
```
Copy icon
Copy
To run tests on iOS, for example an iPhone 15 or iPhone 16 running iOS 17 or 18, use the following syntax:
```yaml
platforms:
- platformName: ios
deviceName: iPhone 1[56]$
platformVersion: '1[78]'
```
Copy icon
Copy
The following snippet shows how to run a test from a pool of two specific devices:
```yaml
platforms:
- platformName: android
deviceName: Samsung Galaxy A52|Xiaomi Redmi Note 8
platformVersion: '9.0|11.0'
```
Copy icon
Copy
The BrowserStack SDK is a plug-n-play solution that handles all the setup for you. It is the recommended integration method for your project. To learn more, see the SDK core concepts page .
Capability
Required/Optional
Description
Sample values
platformName
Required
The mobile operating system to test on.
android or ios
deviceName
Required
The device name, or a regular expression. A matching device is allocated based on your pattern.
Samsung .* allocates any Samsung device. iPhone 1[56]$ allocates an iPhone 15 or iPhone 16.
platformVersion
Optional
The major OS version, or a range of OS versions specified as regex.
1[012] allocates version 10, 11, or 12.
deviceType
Optional
The form factor of the device.
phone or tablet.
Note the following when using the platformVersion capability:
Minor and patch OS versions are not honored in the platformVersion capability.
Escape characters are not supported.
DesiredCapabilities capabilities = new DesiredCapabilities ();
capabilities . setCapability ( "platformName" , "android" );
capabilities . setCapability ( "deviceName" , "Samsung Galaxy S.*" );
capabilities . setCapability ( "platformVersion" , "1[012]" );
var capabilities = {
" platformName " : " android " ,
" deviceName " : " Samsung Galaxy S.* " ,
" platformVersion " : " 1[012] " ,
}
AppiumOptions capabilities = new AppiumOptions ();
Dictionary < string , object > browserstackOptions = new Dictionary < string , object >();
capabilities . AddAdditionalCapability ( "platformName" , "android" );
capabilities . AddAdditionalCapability ( "deviceName" , "Samsung Galaxy S.*" );
capabilities . AddAdditionalCapability ( "platformVersion" , "1[012]" );
desired_cap = {
"platformName" : "android" ,
"deviceName" : "Samsung Galaxy S.*" ,
"platformVersion" : "1[012]" ,
}
capabilities = {
"platformName" => "android" ,
"deviceName" => "Samsung Galaxy S.*" ,
"platformVersion" => "1[012]" ,
}
DesiredCapabilities capabilities = new DesiredCapabilities ();
capabilities . setCapability ( "platformName" , "ios" );
capabilities . setCapability ( "deviceName" , "iPhone 1[56]$" );
capabilities . setCapability ( "platformVersion" , "1[78]" );
var capabilities = {
" platformName " : " ios " ,
" deviceName " : " iPhone 1[56]$ " ,
" platformVersion " : " 1[78] " ,
}
AppiumOptions capabilities = new AppiumOptions ();
Dictionary < string , object > browserstackOptions = new Dictionary < string , object >();
capabilities . AddAdditionalCapability ( "platformName" , "ios" );
capabilities . AddAdditionalCapability ( "deviceName" , "iPhone 1[56]$" );
capabilities . AddAdditionalCapability ( "platformVersion" , "1[78]" );
desired_cap = {
"platformName" : "ios" ,
"deviceName" : "iPhone 1[56]$" ,
"platformVersion" : "1[78]" ,
}
capabilities = {
"platformName" => "ios" ,
"deviceName" => "iPhone 1[56]$" ,
"platformVersion" => "1[78]" ,
}
Capability
Required/Optional
Description
Sample values
OS
Required
The mobile operating system to test on.
android or ios
device
Required
The device name, or a regular expression. A matching device is allocated based on your pattern.
Samsung .* allocates any Samsung device. iPhone 1[56]$ allocates an iPhone 15 or iPhone 16.
os_version
Optional
The major OS version, or a range of OS versions specified as regex.
1[012] allocates version 10, 11, or 12.
deviceType
Optional
The form factor of the device.
phone or tablet.
Note the following when using the platformVersion capability:
Minor and patch OS versions are not honored in the os_version capability.
Escape characters are not supported.
DesiredCapabilities capabilities = new DesiredCapabilities ();
capabilities . setCapability ( "platform" , "android" );
capabilities . setCapability ( "device" , "Samsung Galaxy S.*" );
capabilities . setCapability ( "os_version" , "1[012]" );
var capabilities = {
" platform " : " android " ,
" device " : " Samsung Galaxy S.* " ,
" os_version " : " 1[012] " ,
}
AppiumOptions capabilities = new AppiumOptions ();
Dictionary < string , object > browserstackOptions = new Dictionary < string , object >();
capabilities . AddAdditionalCapability ( "platform" , "android" );
capabilities . AddAdditionalCapability ( "device" , "Samsung Galaxy S.*" );
capabilities . AddAdditionalCapability ( "os_version" , "1[012]" );
desired_cap = {
"platform" : "android" ,
"device" : "Samsung Galaxy S.*" ,
"os_version" : "1[012]" ,
}
desired_caps = {
"platform" => "android" ,
"device" => "Samsung Galaxy S.*" ,
"os_version" => "1[012]" ,
}
DesiredCapabilities capabilities = new DesiredCapabilities ();
capabilities . setCapability ( "platform" , "ios" );
capabilities . setCapability ( "device" , "iPhone 1[56]$" );
capabilities . setCapability ( "os_version" , "1[78]" );
var capabilities = {
" platform " : " ios " ,
" device " : " iPhone 1[56]$ " ,
" os_version " : " 1[78] " ,
}
AppiumOptions capabilities = new AppiumOptions ();
Dictionary < string , object > browserstackOptions = new Dictionary < string , object >();
capabilities . AddAdditionalCapability ( "platform" , "ios" );
capabilities . AddAdditionalCapability ( "device" , "iPhone 1[56]$" );
capabilities . AddAdditionalCapability ( "os_version" , "1[78]" );
desired_cap = {
"platform" : "ios" ,
"device" : "iPhone 1[56]$" ,
"os_version" : "1[78]" ,
}
desired_caps = {
"platform" => "ios" ,
"device" => "iPhone 1[56]$" ,
"os_version" => "1[78]" ,
}
To run a test on a single device from a pool of devices, see run tests on a single device on App Automate .
Is this page helping you?
Thank you for your valuable feedback!