. Emprunts 319 811 | 27,79 51 478 | 5.84
I want to capture on the same row 319 811 51 478
ORGROUP 1 319 811" group2 51 478
. Emprunts 51 478 | 5.84
Can someo,ne help me ?GROUP 1 "" group2 51478

ORGROUP 1 319 811" group2 51 478
Can someo,ne help me ?GROUP 1 "" group2 51478
I assume that the numbers given here use space as the thousands separator?Here is my text
. Emprunts 319 811 | 27,79 51 478 | 5.84
I want to capture on the same row 319 811 51 478ORGROUP 1 319 811" group2 51 478
. Emprunts 51 478 | 5.84Can someo,ne help me ?GROUP 1 "" group2 51478
So this can go for the first case.Code: Select all
EnableExplicit If Not CreateRegularExpression(0, "(\d[\d ]+\d).+? (\d[\d ]+\d)") Debug RegularExpressionError() : End EndIf Define Txt$ = ". Emprunts 319 811 | 27,79 51 478 | 5.84" If Not ExamineRegularExpression(0, Txt$) Debug "Nothing" : End EndIf Define i While NextRegularExpressionMatch(0) i + 1 Debug "#1 [" + RegularExpressionGroup(0, 1) + "]" Debug "#2 [" + RegularExpressionGroup(0, 2) + "]" Wend FreeRegularExpression(0) EndBut you don't say in which case you're taking the last or penultimate number as the second argument ?Code: Select all
#1 [319 811] #2 [51 478]

In factj the second test will return group1 "" group2 57811Define Txt$ = ". Emprunts 319 811 | 27,79 51 478 | 5.84"
Define Txt$ = ". 51 478 | 5.84"
in the second test 51478 will be in the same position as first test and in the first position 319 811 they will be nothing
Code: Select all
EnableExplicit
Structure Group_Structure
Group1$
Group2$
EndStructure
Procedure.i SeparateGroups(Txt$, *Group.Group_Structure)
Protected Result.i, Help$, Pos.i
If FindString(Txt$, "Emprunts")
Help$ = RemoveString(Txt$, "Emprunts")
Help$ = RemoveString(Help$, ".")
*Group\Group1$ = RemoveString(StringField(Help$, 1, "|"), " ")
Result = 1
Help$ = Trim(StringField(Help$, 2, "|"))
Pos = FindString(Help$, " ")
If Pos
Help$ = Mid(Help$, Pos)
*Group\Group2$ = RemoveString(Help$, " ")
Result + 1
EndIf
Else
Help$ = RemoveString(Txt$, " ")
Help$ = RemoveString(Help$, ".")
*Group\Group2$ = StringField(Help$, 1, "|")
If *Group\Group2$ <> ""
Result = 1
EndIf
EndIf
ProcedureReturn Result
EndProcedure
Define Group.Group_Structure
Define Txt$
If SeparateGroups(". Emprunts 319 811 | 27,79 51 478 | 5.84", @Group)
Debug "1: " + Group\Group1$ + " 2: " + Group\Group2$
EndIf
Group\Group1$ = ""
Group\Group2$ = ""
If SeparateGroups(". 51 478 | 5.84", @Group)
Debug "1: " + Group\Group1$ + " 2: " + Group\Group2$
EndIf
Code: Select all
EnableExplicit
Procedure Extract_Values(Txt$, RegEx$)
Protected Tmp_1$, Tmp_2$
Debug "Txt: [" + Txt$ + "]"
If Not CreateRegularExpression(0, RegEx$)
Debug RegularExpressionError() : ProcedureReturn
EndIf
If Not ExamineRegularExpression(0, Txt$)
Debug "Nothing" : ProcedureReturn
EndIf
Debug " Found: " + CountRegularExpressionGroups(0)
While NextRegularExpressionMatch(0)
Tmp_1$ = RemoveString(RegularExpressionGroup(0, 1), " ")
Tmp_2$ = RemoveString(RegularExpressionGroup(0, 2), " ")
Debug " #1 [" + Tmp_1$ + "]"
Debug " #2 [" + Tmp_2$ + "]"
Wend
FreeRegularExpression(0)
Debug ""
EndProcedure
Extract_Values(". Emprunts 319 811 | 27,79 51 478 | 5.84",
"(\d[\d ]+\d).+? (\d[\d ]+\d)")
Extract_Values(". Emprunts 51 478 | 5.84",
"() ([\d ]+) \|")
End
Code: Select all
Txt: [. Emprunts 319 811 | 27,79 51 478 | 5.84]
Found: 2
#1 [319811]
#2 [51478]
Txt: [. Emprunts 51 478 | 5.84]
Found: 2
#1 []
#2 [51478]

My expression seems working with rexman and don't work with purebasicchaine1.s="378 632| 7,96 468 002 | 22:56""
chaine1.s = chaine1.s="1 378 632| 7,96 1 468 002 | 22:56"
chaine1.s = chaine1.s="1632| 7,96 1 468 002 | 22:56"
Code: Select all
chaine1.s=" 1 378 632| 7,96 468 002 | 22:56"
If CreateRegularExpression(0, "([-| ]\d{1,3}\s{0,9}\d{1,3}.\d{1,3}\s{0,9})|(\d{1,4}\s{0,}[|])", #PB_RegularExpression_Extended)
Dim Result$(0)
NbFound = ExtractRegularExpression(0, chaine1, Result$())
; Debug nbfound
If nbfound >0
For i=0 To NbFound-1
If i=0
result$(i)= ReplaceString(result$(i),"|",Space(0))
; Debug chaine1
; Debug result$(i)
mont11.s =ReplaceString(result$(i), Chr(32), Space(0))
ElseIf i=2
result$(i)= ReplaceString(result$(i),"|",Space(0))
mont22.s =ReplaceString(result$(i), Chr(32), Space(0))
EndIf
Next
FreeRegularExpression(0)
FreeArray(result$())
Else
; Debug RegularExpressionError()
EndIf
EndIf
Debug mont11
Debug mont22Code: Select all
EnableExplicit
#re = 0
Define NbFound, txt$, i
Define Dim Result$(0)
txt$ = ". Emprunts 319 811 | 27,79 51 478 | 5.84"
If CreateRegularExpression(#re, "(?<=\h)[\d\h]+?(?=\|)")
NbFound = ExtractRegularExpression(#re, txt$, Result$())
For i = 0 To NbFound - 1
Result$(i) = ReplaceString(Result$(i), " ", "")
Debug Val(Result$(i))
Next
EndIf
thankstxt$ = ". Emprunts -811 | 27,79 51 478 | 5.84"

I want to test the var 779 that will be obligatory like 7.79 or 7.79txt$ = ". Emprunts -811 | 779 51 478 | 5.84"
Code: Select all
(?<=\h)(-?[\d\h]+?)(?:\|\h?[\d,.]+?)