regexreplace - Looks for text in the text using the regular expression pattern and replaces it with the specified text.
regexstart - Finds the starting position of the found fragment. Only works with regexsearch . This function can be used only after calling regexsearch
regexend - Recognizes the finishing position of the found fragment. Only works with regexsearch . This function can be used only after calling regexsearch
Detailed syntax and interactive examples where you can customize check and expression
Syntax:
regexsearch is called with a different number of parameters.
The first challenge is this:
CODE:
regexsearch (1, #P[0], T, R);
or
CODE:
regexsearch (1, #P[0], T, R, IGNORECASE | SINGLELINE | MULTILINE | GLOBAL | RIGHTTOLEFT | EXTENDED);
The first parameter is the desired number of fragments found. When -1 is searched for all.
The second is a pointer to string or an array of string (if more than one is searched) into which the found fragment will be written.
The third is the string that contains the text we are looking for.
The fourth is the string of the string of the regular expression.
Subsequent calls, if we did not search for the first occurrence of all occurrences, comes with two parameters.
CODE:
regexsearch (-1, #P [0]);
The first parameter is the desired number of fragments found. When -1 is searched for all.
The second is a pointer to string or an array of string (if more than one is searched) into which the found fragment will be written.
For each subsequent call, the following fragment will be searched.
The regexsearch function returns the number of fragments found or 0 if not found.
regexreplace is also called with a different number of parameters.
The first challenge is this:
CODE:
regexreplace (-1, #P, T, R, M);
or
CODE:
regexreplace (-1, #P, T, R, M, IGNORECASE | SINGLELINE | MULTILINE | GLOBAL | RIGHTTOLEFT | EXTENDED);
The first parameter is the desired number of replaceable fragments. When -1 replaces all.
The second is a pointer to string, in which the changed text will be written.
The third line is string, which contains the source text in which we replace. This text remains unchanged
The fourth is the string of the string of the regular expression, the fragment of which in the text will be replaced.
Fifth - The string string, in which the text will be replaced.
If you do not need to save the source text, you can use the same variable as the second and third parameter. Then the changed text will be overwritten in the source.
Subsequent calls, if we did not replace everything on the first call of all occurrences, comes with two parameters.
CODE:
regexreplace (2, #P);
The first parameter is the desired number of fragments found. When -1 is searched for all.
The second is a pointer to string or an array of string (if more than one is searched) into which the replaced text will be written.
For each subsequent call, the following fragment will be replaced.
The regexreplace function returns 1 if there was a replacement or 0 if it was not.
regexstart and regexend are called with a different number of parameters, depending on how they are used.
One challenge:
CODE:
regexstart (#Pos_start [0]);
Parameter - Pointer to an int or an array of int, into which the starting positions of the found fragments will be written. An array to allocate at least the number of fragments.
Returns the number of fragments found, like regexsearch .
CODE:
regexend (#Pos_end [0]);
Parameter - Pointer to an int or an array of int, in which the finishing positions of the found fragments are written. An array to allocate at least the number of fragments.
Returns the number of fragments found, like regexsearch .
The second call is used if you need to know the position of only one selected fragment:
CODE:
regexstart (2);
A parameter is a number indicating the position of which fragment you need to know.
In this example, we learn the starting position of 3 elements.
Returns the position of the element or -1 if this element is not present.
CODE:
regexend (2);
A parameter is a number indicating the position of which fragment you need to know.
In this example, we learn the finishing position of 3 elements.
Returns the position of the element or -1 if this element is not present.
Examples:
Looking for one by one
CODE:
string P;
string T="1 USD Курс Доллара 66,8932 0,516 66,3772" +formatic(13)+formatic(10)+ "1 EUR Курс Евро 76,0576 0,8323 75,2253 Курс Гривны 0,0005"; // строка, в которой ищем
string R="Курс.*?(\d+[,.]\d+)";//регулярное выражение
if (regexsearch(1, #P, T, R)!=0)
{
messagebox (P);
while (regexsearch(1, #P)!=0)
{
messagebox (P);
}
}
string T="1 USD Курс Доллара 66,8932 0,516 66,3772" +formatic(13)+formatic(10)+ "1 EUR Курс Евро 76,0576 0,8323 75,2253 Курс Гривны 0,0005"; // строка, в которой ищем
string R="Курс.*?(\d+[,.]\d+)";//регулярное выражение
if (regexsearch(1, #P, T, R)!=0)
{
messagebox (P);
while (regexsearch(1, #P)!=0)
{
messagebox (P);
}
}
We are looking for everything and write to the array
CODE:
string P[10];
string T="1 USD Курс Доллара 66,8932 0,516 66,3772" +formatic(13)+formatic(10)+ "1 EUR Курс Евро 76,0576 0,8323 75,2253 Курс Гривны 0,0005"; // строка, в которой ищем
string R="Курс.*?(\d+[,.]\d+)";//регулярное выражение
int k=regexsearch(-1, #P[0], T, R);
for (int n=0; n<k; n++)
{
messagebox (P[n]);
}
string T="1 USD Курс Доллара 66,8932 0,516 66,3772" +formatic(13)+formatic(10)+ "1 EUR Курс Евро 76,0576 0,8323 75,2253 Курс Гривны 0,0005"; // строка, в которой ищем
string R="Курс.*?(\d+[,.]\d+)";//регулярное выражение
int k=regexsearch(-1, #P[0], T, R);
for (int n=0; n<k; n++)
{
messagebox (P[n]);
}
Find in the line the text between value "and </div>
CODE:
string P;
string T="<div class="+formatic(34)+"info-value"+formatic(34)+">Odessa</div>"; // the line we are looking for
string R="(?<=value\"+formatic(34)+">)"+"(.*)+(?=</div>)";//regular expression.
if (regexsearch(1, #P, T, R)==1)messagebox (P );
string T="<div class="+formatic(34)+"info-value"+formatic(34)+">Odessa</div>"; // the line we are looking for
string R="(?<=value\"+formatic(34)+">)"+"(.*)+(?=</div>)";//regular expression.
if (regexsearch(1, #P, T, R)==1)messagebox (P );
The search is clean between WR, but WR is not output to the result
CODE:
string P[10];
string T="WR555WR WRworldWR 777 df WR222WR"; // строка, в которой ищем
string R="(?<=WR)[0-9]+(?=WR)";//регулярное выражение. WR не выводится в результат
int k=regexsearch(-1, #P[0], T, R);
for (int n=0; n<k; n++)
{
messagebox (P[n]);
}
string T="WR555WR WRworldWR 777 df WR222WR"; // строка, в которой ищем
string R="(?<=WR)[0-9]+(?=WR)";//регулярное выражение. WR не выводится в результат
int k=regexsearch(-1, #P[0], T, R);
for (int n=0; n<k; n++)
{
messagebox (P[n]);
}
Different variables for source and destination
CODE:
string T="qwertАБВqwertАБВ"; // строка, в которой заменяем
string R="[А-Я]";//Что заменяем (регулярное выражение)
string M="ГаВ";//Чем заменяем
string P;//Сюда запишем измененный текст
int k=regexreplace(2, #P, T, R, M);
messagebox (k);
messagebox (P);
k=regexreplace(-1, #P);
messagebox (k);
messagebox (P);
string R="[А-Я]";//Что заменяем (регулярное выражение)
string M="ГаВ";//Чем заменяем
string P;//Сюда запишем измененный текст
int k=regexreplace(2, #P, T, R, M);
messagebox (k);
messagebox (P);
k=regexreplace(-1, #P);
messagebox (k);
messagebox (P);
One variable for source and receiver
CODE:
string T="qwertАБВqwertАБВ"; // строка, в которой заменяем
string R="[А-Я]";//Что заменяем (регулярное выражение)
string M="ГаВ";//Чем заменяем
int k=regexreplace(2, #T, T, R, M);
messagebox (k);
messagebox (T);
k=regexreplace(-1, #T);
messagebox (k);
messagebox (T);
string R="[А-Я]";//Что заменяем (регулярное выражение)
string M="ГаВ";//Чем заменяем
int k=regexreplace(2, #T, T, R, M);
messagebox (k);
messagebox (T);
k=regexreplace(-1, #T);
messagebox (k);
messagebox (T);