OVERVIEW

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.
CSVregexstringstrings

Pineライブラリ

TradingViewの精神に則り、作者はPineコードをオープンソースライブラリとして公開し、コミュニティの他のPineプログラマーが再利用できるようにしました。作者に敬意を表します!このライブラリを個人的に、または他のオープンソースの投稿で使用することができますが、このコードを投稿で再利用するには、ハウスルールに準拠する必要があります。

免責事項