%RxReplaceStr function




Function

The function replaces the predefined number of substrings in the input text, that match the specified regular expression, with another substring.

Declaration
TEXT %RxReplaceStr(
   TEXT in Text, 
   TEXT in regExp,
   TEXT	in subStr,
   INT	in from := 1,
   INT	in count := 0
 )
Parameters
textText, in which will be the replacement.
regExpA regular expression, which will be replaced in the input parameter text.
substrSubstring, which will replace the found substring that matches the regular expression.
fromIndex, from which the input text is to be searched ( (0 = from start) (optional input parameter).
countNumber of occurrences to be replaced (0 = all occurrences) (optional input parameter).
Example

The function returns a string, in which count occurrences of regular expression regExp will be replaced by substring substr, while input text will be searched from the index from. If some of the input parameters is invalid, the function returns an undefined value.

 


%RxReplaceStr("text some text",  "[a-z]+", "(X)")			;returns text: (X) (X) (X)
%RxReplaceStr("text some text",  "[a-z]+", "(X)", 1, 0)		;returns text: (X) (X) (X)
%RxReplaceStr("text some text",  "[a-z]+", "(X)", 1, 2)		;returns text: (X) (X) text
%RxReplaceStr("text some text",  "[a-z]+", "(X)", 2, 1)		;returns text: t(X) some text
%RxReplaceStr("text some text",  "[a-z]+", "(X)", 5, 1)		;returns text: text (X) text
%RxReplaceStr("text some text",  "[a-z]+", "(X)", 20, 0)	;returns text: text some text
%RxReplaceStr("text some text",  "[a-z]+", "(X)", 0, 20)	;returns text: (X) (X) (X)

2 Comments

  1. Anonymous

    1) Neskodily by uviest link ake regularne vyrazy su podporovane

    2) Hodily by sa aj ine priklady napr. ako v "M..meno..sufix" nahradit retazec "..meno.." inym retazcom nakolko znak "." v reg.vyrazoch reprezentuje prave jeden znak a potom Vykonanie funkcie %RxReplaceStr("M..meno..sufix", "..*..", ".other.") ma za vysledok retazec "other" namiesto ocakavaneho "M.other.sufix" ...

  2. DS: Dobrý deň,

    1. Pre prácu s regulárnymi výrazmi je použitá knižnica GNAT.REGPAT, podrobnejšie informácie ohľadom syntaxe možno nájsť na nasledujúcom odkaze - http://gnuada.sourceforge.net/source-gcc-4.2.2/g-regpat__ads.html
    2. Presne tak, znak "." má v regulárnych výrazoch špeciálny význam, je potrebné použiť špeciálnu syntax, bližšie info tu - https://stackoverflow.com/questions/45108610/extract-string-between-two-dots 
      Riešenie na Váš problém by teda vyzeralo nasledovne: %RxReplaceStr("M..meno..sufix", "\..([^\.]+)\..", ".other.")
    1. You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.