Skip to content
Algo Trade Analytics Docs

str.match() - Pine Script Function

Returns the new substring of the source string if it matches a regex regular expression, an empty string otherwise.

str.match(source, regex) → simple string
NameTypeDescription
sourcesimple stringSource string.

The new substring of the source string if it matches a regex regular expression, an empty string otherwise.

  • Function returns first occurrence of the regular expression in the source string.
//@version=6
indicator("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.islastconfirmedhistory
label.new(bar_index, high, text = tickerid) // "NASDAQ:AAPL"