str.match() - Pine Script Function
str.match()
Section titled “str.match()”Overview
Section titled “Overview”Returns the new substring of the source string if it matches a regex regular expression, an empty string otherwise.
Syntax
Section titled “Syntax”str.match(source, regex) → simple stringParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| source | simple string | Source string. |
Returns
Section titled “Returns”The new substring of the source string if it matches a regex regular expression, an empty string otherwise.
Remarks
Section titled “Remarks”- Function returns first occurrence of the regular expression in the source string.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("str.match")s = input.string("It's time to sell some NASDAQ:AAPL!")// finding first substring that matches regular expression "[\w]+:[\w]+"var string tickerid = str.match(s, "[\\w]+:[\\w]+")if barstate.islastconfirmedhistorylabel.new(bar_index, high, text = tickerid) // "NASDAQ:AAPL"