Page 1 of 1

Regular expression

Posted: Tue May 30, 2023 9:49 am
by a_carignan
Hello,
The following code :

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - RegularExpression example file
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;

; Will match every word of 3 letters, lowercase with a 'b' as middle letter
;
If CreateRegularExpression(0, Chr(34)+".*"+ Chr(34))

  Dim Result$(0)
  
  NbResults = ExtractRegularExpression(0, Chr(34)+"alain"+Chr(34)+" "+Chr(34)+"allo"+Chr(34), result$())
  
  Debug "Nb matchs found: " + NbResults
  
  For i = 0 To NbResults - 1
    Debug Result$(i)
  Next

Else
  MessageRequester("Error", RegularExpressionError())
EndIf

Returns as result :
Nb matchs found: 1
"alain" "allo"
The result I'm looking for is :
Nb matchs found: 2
"alain"
"allo"
Thank you in advance for your help.

Re: Regular expression

Posted: Tue May 30, 2023 10:21 am
by Marc56us

Code: Select all

If CreateRegularExpression(0, Chr(34)+"\w+"+ Chr(34))

Code: Select all

Nb matchs found: 2
"alain"
"allo"

Re: Regular expression

Posted: Tue May 30, 2023 10:22 am
by AZJIO

Code: Select all

#q$ = Chr(34)
If CreateRegularExpression(0, #q$+".*?"+#q$)
If CreateRegularExpression(0, Chr(34)+".*?"+ Chr(34))

Code: Select all

If CreateRegularExpression(0, ~"\"[^\"]*\"")
If CreateRegularExpression(0, Chr(34)+"[^"+Chr(34)+"]*"+Chr(34))

Re: Regular expression

Posted: Tue May 30, 2023 11:12 am
by a_carignan
Thank you all! :D

Re: Regular expression

Posted: Tue May 30, 2023 11:34 am
by mk-soft

Code: Select all

#q$ = Chr(34)

Debug #q$
Debug #DQUOTE$

Re: Regular expression

Posted: Tue May 30, 2023 11:45 am
by AZJIO
I even met this, but the $ sign additionally indicates that this is a string.

Code: Select all

#q = Chr(34)
Debug #q

Re: Regular expression

Posted: Tue May 30, 2023 11:47 am
by NicTheQuick
Is usually use escaped strings:

Code: Select all

Debug ~"\"alain\""

Re: Regular expression

Posted: Tue May 30, 2023 2:12 pm
by mk-soft
There is ready constant '#DQUOTE$'

Re: Regular expression

Posted: Sat May 04, 2024 9:32 pm
by a_carignan
THANKS

Re: Regular expression

Posted: Mon May 06, 2024 9:45 am
by NicTheQuick
A year later :lol: