# Extract Text from Screen

You can easily extract text from any UI element on the device screen and store it in a variable for later use in your test.

**Test Steps:**

1. **Select the Element:** While in recording or inspection mode, click on the desired element on the device screen. A green box will highlight the selected element.
2. **Choose the Extraction Action:** A context menu will appear with several interaction options. Select **"Extract text to a variable"**.

A new step will be added to your test flow, which will save the text from the selected element (in this case, "Constans II (son of Constantine III)") into a variable when the test is run.

<figure><img src="https://3741940050-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYlJodSwxTIBbHmZhKEX5%2Fuploads%2Fu3yAM8gBhCDwB519UMeR%2FScreenshot%202025-08-06%20at%2010.34.53%E2%80%AFAM.png?alt=media&#x26;token=9e32c7c1-e8ad-47f2-a700-4f129d312b20" alt=""><figcaption></figcaption></figure>

## Using Regex for Text Extraction

You can also extract specific text patterns from strings

<figure><img src="https://3741940050-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYlJodSwxTIBbHmZhKEX5%2Fuploads%2F9yriguhlFrkbalvDExk4%2FScreenshot%202025-08-06%20at%2010.49.16%E2%80%AFAM.png?alt=media&#x26;token=5d12126d-4f2d-4db4-a3db-f9b7e50084c5" alt="" width="375"><figcaption></figcaption></figure>

Need help creating a regex pattern? Click on **Use AI to write regex** to ask Finalrun AI to generate one for you based on your requirements, then use it directly in our platform.

<figure><img src="https://3741940050-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYlJodSwxTIBbHmZhKEX5%2Fuploads%2FEKtgYoWicCTXAdxUac0I%2FScreenshot%202025-08-06%20at%2010.49.49%E2%80%AFAM.png?alt=media&#x26;token=51a30063-b034-430f-af2a-1daee0fb6d5a" alt="" width="375"><figcaption></figcaption></figure>

### Examples

#### Example 1: Extracting amount&#x20;

```regex
Pattern: ₹\s*([0-9]+)
Input: ₹100
Output: 100
```

#### Example 2: Extracting Phone Numbers

```
Pattern: (\d{3}[-.\s]?\d{3}[-.\s]?\d{4})
Input: Call us at 555-123-4567 or 555.987.6543 for more information.
Output: 555-123-4567
```

#### Example 3: Extracting URLs

```
Pattern: (https?://[^\s]+)
Input: Visit our website at https://example.com or http://demo.example.org for more details.
Output: https://example.com
```

#### Example 4: Named Capture Groups

```
Pattern: (?<username>[a-zA-Z0-9_]+):(?<message>.+)
Input: john_doe: Hello world! alice_smith: How are you?
Output: username: john_doe, message: Hello world!
```

#### Example 5: Extracting Dates

```
Pattern: (\d{1,2}/\d{1,2}/\d{2,4})
Input: The meeting is scheduled for 10/15/2023 and the deadline is 12/31/2023.
Output: 10/15/2023
```

#### Example 6: Extracting Product Codes

```
Pattern: ([A-Z]{2}-\d{4})
Input: Please reorder products AB-1234 and CD-5678 before next month.
Output: AB-1234
```

#### Example 7: Extracting Hashtags

```
Pattern: (#\w+)
Input: Check out our new product launch #NewRelease #Innovation #Tech
Output: #NewRelease
```

#### Example 8: Extracting Time

```
Pattern: (\d{1,2}:\d{2}(?::\d{2})?\s*(?:AM|PM)?)
Input: The meeting starts at 9:30 AM and ends at 11:45 AM.
Output: 9:30 AM
```

#### Example 9: Extracting Names

```
Pattern: (Mr\.|Ms\.|Mrs\.|Dr\.)\s([A-Z][a-z]+)
Input: Dr. Smith and Mrs. Johnson will attend the conference.
Output: Dr. Smith
```

#### Example 10: Extracting IP Addresses

```
Pattern: (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})
Input: The server IP addresses are 192.168.1.1 and 10.0.0.1
Output: 192.168.1.1
```



### Features Not Covered

Our platform focuses on text extraction and does not support:

* Lookahead/lookbehind assertions
* Atomic grouping
* Conditional patterns
* Advanced backtracking controls

