Match Regex returns non-matching results

Hi guys,

I experienced strange behaviour in the Match Regex function. I get both true as a function result and an empty position array. From what I understood this should be impossible.

Here is the code:
Code :
ARRAY LONGINT($pos_found_array;0)
ARRAY LONGINT($length_found_array;0)
$regexResult:=Match regex("\D";$verwZweck;$pos;$pos_found_array;$length_found_array) // eha 24.01.2019
If ($regexResult & (Size of array($pos_found_array)=0))
//Impossibal - to the forums
End if

The goal is to extract the number 1234567890 from the string. I got the start position beforehand and need to find the first non digit character starting at position 52 in order to determine the end of the number.

With our Regex component :

Here the pattern to use with the extract method to achieve your goal

<code 4D>
$regex:=New regex
$str:=New object
$ collection
$ string(“3”;",";sk ignore empty strings)
</code 4D>


I think you must capture something with your pattern to get position & length.
“(\D)” seems to work

Hello again,

the missing brackets were the problem! Thank you very much, now it is working as it is supposed to.

Hi Johannes,
I hope you won’t mind a reply in english.
The goal of using arrays parameters in match regex is to collect “sub pattern(s) inside the main pattern”. As your pattern has no sub patterns (limited by parenthesis), the use of this syntax with arrays ($ar_pos;$ar_length) has no sense.

With this example, you’ll get how it works:
<code 4D>
$str_t:=“1234567 8901234 5678901 2345678”
$regex_t:="(\d{7}) (\d{7})"
//main pattern is 2 groups of 7 digits separated by a space
//inside this main pattern we will capture each group of 7 digits
while(Match regex($regex_t;$str_t;$start_t;$ar_pos;$ar_length))
$main_t:=Substring($str_t;$start_t;$ar_pos{0};$ar_length{0}) //main
$group1_t:=Substring($str_t;$start_t;$ar_pos{1};$ar_length{1}) //capture group1
$group2_t:=Substring($str_t;$start_t;$ar_pos{2};$ar_length{2}) //capture group2
$start_t:=$ar_pos{0}+$ar_length{0}+1 //next
end while
</code 4D>