String.search
String.search
Function
Finds the first occurrence of a string or regular expression in the current string.
Syntax
string.search(pattern)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| pattern | String/Regex | No | '' | The string or regular expression to find. |
Return value
| Type | Description |
|---|---|
| Int | Returns the starting byte position if found; returns -1 if not found. |
Example
text = 'hello BT' result = text.search('BT') // Output: 6 print result
Notes
- The return value is calculated as a UTF-8 byte offset.