This library contains regular expression (regex) search functions which are helpful, in particular, in reading configuration inputs.
feedRgx(): Searches for the first occurrence of `regex` pattern in the `src` and returns `src` split into parts as a tuple: `[<before the match>, <match>, <after the macth>]`. If no match returns `[src, "", ""]`
countRgx(): Counts `regex` occurrences in the `src`.
matchRgx(): Finds given `occurence` of `regex` pattern in `src` string.
NB!countRgx() and matchRgx() do not support `^` (beginning of the string placeholder), lookbehind some other complex patterns, because they works by cutting off the part of the string up to the first found occurence (inclusive) and then continuing the search on the remainder of the string. E.g. in a four line source `(?<=\n).+\n` should match the second and the third lines but matchRgx only matches the second line since after matching it continues to search in the remainder AFTER the match only.
█ FULL LIST OF FUNCTIONS AND PARAMETERS
method feedRgx(src, regex) Searches for the first occurrence of `regex` pattern in the `src` and returns `src` split into parts as a tuple: `[<before the match>, <match>, <after the macth>]`. If no match returns `[src,"",""]` Namespace types: series string, simple string, input string, const string Parameters: src (string): (string) String to search for the regex pattern regex (string): (string) RegEx pattern Returns: A tuple `[begS, matchS, endS]` where `begS` is the part of the `src` string from the beginning up to the first occurence of the `regex` pattern (or up to the end if not found), `matchS` - the first occurrence of the regex pattern and `endS` the part of the strinf following the first occurrence of the `regex` pattern.
method countRgx(src, regex) Counts `regex` occurrences in the `src`. ___NB!___ _Does not support `^` (beginning of the string placeholder), lookbehind some other complex patterns, because it works by cutting off the part of the string up to the first found occurence (inclusive) and then continuing the search on the remainder of the string. E.g. in a four line source `(?<=\n).+\n` should match the second and the third lines but matchRgx only matches the second line since after matching it continues to search in the remainder AFTER the match only. _ Namespace types: series string, simple string, input string, const string Parameters: src (string): (string) String in which the regex pattern occurences are to be counted regex (string): (string) RegEx pattern Returns: The number of occurrences of the `regex` pattern in the `src` string.
method matchRgx(src, regex, occurrence) Finds given `occurence` of `regex` pattern in `src` string. ___NB!___ _Does not support `^` (beginning of the string placeholder), lookbehind and some other complex patterns, because it works by cutting off the part of the string up to the first found occurence (inclusive) and then continuing the search on the remainder of the string. E.g. in a four line source `(?<=\n).+\n` should match the second and the third lines but matchRgx only matches the second line since after matching it continues to search in the remainder AFTER the match only. _ Namespace types: series string, simple string, input string, const string Parameters: src (string): (string) String to search for the regex pattern regex (string): (string) RegEx pattern occurrence (int): (int) (Default is 1) The number of the occurrence to search for. If this params exceeds the actual number of occurrences of the pattern in the `src` string the following tuple is returned [na, src length, na] Returns: [matchS , matchPos, matchL] A tuple, matchS - matched substring, matchPos - position of the match, matchL - match length
█ HOW TO USE
See DEMO section in the script. You can test regex patterns by playing around with script input settings. Another usage example can be found in my CSVParser and HTFMAs libraries.
發行說明
v2
Added: method csvToArS(this) method csvToArF(this) method csvToArI(this) Returns a string/float/int array of CSV values Parameters: this (string): (string) String of comma separated values Returns: A string/float/int array of values from `this` string.
Pine腳本庫
秉持 TradingView 一貫的共享精神,作者將此 Pine 程式碼發佈為開源庫,讓社群中的其他 Pine 程式設計師能夠重複使用。向作者致敬!您可以在私人專案或其他開源發佈中使用此庫,但在公開發佈中重複使用該程式碼需遵守社群規範。