Regular expression

Just starting out? Need help? Post your questions and find answers here.
User avatar
a_carignan
User
User
Posts: 81
Joined: Sat Feb 21, 2009 2:01 am
Location: Canada

Regular expression

Post 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.
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: Regular expression

Post by Marc56us »

Code: Select all

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

Code: Select all

Nb matchs found: 2
"alain"
"allo"
AZJIO
Addict
Addict
Posts: 1312
Joined: Sun May 14, 2017 1:48 am

Re: Regular expression

Post 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))
User avatar
a_carignan
User
User
Posts: 81
Joined: Sat Feb 21, 2009 2:01 am
Location: Canada

Re: Regular expression

Post by a_carignan »

Thank you all! :D
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Regular expression

Post by mk-soft »

Code: Select all

#q$ = Chr(34)

Debug #q$
Debug #DQUOTE$
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
AZJIO
Addict
Addict
Posts: 1312
Joined: Sun May 14, 2017 1:48 am

Re: Regular expression

Post by AZJIO »

I even met this, but the $ sign additionally indicates that this is a string.

Code: Select all

#q = Chr(34)
Debug #q
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Regular expression

Post by NicTheQuick »

Is usually use escaped strings:

Code: Select all

Debug ~"\"alain\""
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Regular expression

Post by mk-soft »

There is ready constant '#DQUOTE$'
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply