Cant find the regex

Hi,

Here’s example of strings I’m supposed to capture:

$T_String:=“AG 1 µ”
$T_String:=“AG 1,5 µ”
$T_String:=“AG 15 µ”

$T_String:=“AG 1-2 µ”
$T_String:=“AG 1,5-2,3 µ”
$T_String:=“AG 15-15,8 µ”

[A string][space][digitwith or not a comma][dash][digitwith or not a comma][space or not] a string

Dash can exist or not
Right and left of the dash: a real number or integer

And I cannot achieve the right pattern :oops:

As a second step, I will capture AG and digit right and left of the dash

Thanks

$rx_t:="(\w{1,30}) (\d{1,4}(,\d{1,4})?)(-\d{1,4}(,\d{1,4})?)? µ"

ARRAY LONGINT($pos_al;0)
ARRAY LONGINT($len_al;0)

C_COLLECTION($test_c)
$test_c:=New collection

$test_c.push(“AG 1 µ”)
$test_c.push(“AG 1,5 µ”)
$test_c.push(“AG 15 µ”)
$test_c.push(“AG 1-2 µ”)
$test_c.push(“AG 1,5-2,3 µ”)
$test_c.push(“AG 15-15,8 µ”)

For each ($test_t;$test_c)
$b:=Match regex($rx_t;$test_t;1;$pos_al;$len_al)
End for each

Works!

Ce motif marche avec tes exemples dans BBEdit :
“(\w+) (\d+,\d+|\d+)(-(\d+|\d+,\d+))? µ”
Puis copier/coller dans 4D où malgré les anti slash surnuméraires, il marche aussi :
<code 4D>
$rx_t:="(\w+) (\d+,\d+|\d+)(-(\d+|\d+,\d+))? µ"
ARRAY LONGINT($pos_al;0)
ARRAY LONGINT($len_al;0)
C_COLLECTION($test_c)
$test_c:=New collection
$test_c.push(“AG 1 µ”)
$test_c.push(“AG 1,5 µ”)
$test_c.push(“AG 15 µ”)
$test_c.push(“AG 1-2 µ”)
$test_c.push(“AG 1,5-2,3 µ”)
$test_c.push(“AG 15-15,8 µ”)
For each ($test_t;$test_c)
ASSERT(Match regex($rx_t;$test_t;1;$pos_al;$len_al))
End for each
</code 4D>