It is currently Thu Oct 22, 2020 6:40 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: RegularExpression ... IT WORKS BUT WHY ??? ;-)
PostPosted: Sat Aug 01, 2020 10:21 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Oct 16, 2009 10:12 am
Posts: 697
Location: BE
Thanks to Michael Vogel :
;https://www.purebasic.fr/english/viewtopic.php?f=12&t=70463&hilit=NextRegularExpressionMatch

regex=CreateRegularExpression(#PB_Any, ~"[\"#a-zA-Z_ ]+")

This character ~ (called tilde I think) makes it work, but it isn't explained in the PB-helpfile in this use.
Neigther something to find in the REGEX pdf (Regular Expressions Cheat Sheet).

Can someone explain how and when this can or must be used, thanks ?

P.s. if you remove it PureBasic will directly show a red character in the string to let you know something is wrong...

_________________
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.


Last edited by Joris on Sat Aug 01, 2020 10:47 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: RegularExpression ... IT WORKS BUT WHY ??? ;-)
PostPosted: Sat Aug 01, 2020 10:37 am 
Offline
Addict
Addict

Joined: Sat Feb 08, 2014 3:26 pm
Posts: 942
Joris wrote:
This character ~ (called tilde I think) makes it work, but it isn't explained in the PB-helpfile in this use.
Neigther something to find in the REGEX pdf (Regular Expressions Cheat Sheet).
Can someone explain how and when this can or must be used, thanks ?
This is escape sequences. See Literal strings
https://www.purebasic.com/documentation ... rules.html
Code:
Literal strings

    Literal strings are declared using the " character.
    Escape sequences are supported using the ~ character before the literal string.
    The allowed escape sequences are:

      \a: alarm           Chr(7)
      \b: backspace       Chr(8)
      \f: formfeed        Chr(12)
      \n: newline         Chr(10)
      \r: carriage return Chr(13)
      \t: horizontal tab  Chr(9)
      \v: vertical tab    Chr(11)
      \": double quote    Chr(34)
      \\: backslash       Chr(92)
Yes, we can use it for a regex.

:wink:

_________________
(English is not my native language, I use an online translator.)


Top
 Profile  
Reply with quote  
 Post subject: Re: RegularExpression ... IT WORKS BUT WHY ??? ;-)
PostPosted: Sat Aug 01, 2020 10:52 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Oct 16, 2009 10:12 am
Posts: 697
Location: BE
But why is this one then wrong ?
regex=CreateRegularExpression(#PB_Any, "[\"#a-zA-Z_ ]+")

_________________
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.


Top
 Profile  
Reply with quote  
 Post subject: Re: RegularExpression ... IT WORKS BUT WHY ??? ;-)
PostPosted: Sat Aug 01, 2020 11:19 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 603
Location: Germany, Saarbrücken
Joris wrote:
But why is this one then wrong ?
regex=CreateRegularExpression(#PB_Any, "[\"#a-zA-Z_ ]+")

Because you can not use double quotes inside a string without escaping them. And therefore you need to use the syntax for escaped strings: ~""

_________________
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: RegularExpression ... IT WORKS BUT WHY ??? ;-)
PostPosted: Sat Aug 01, 2020 2:57 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4973
Location: Germany
If you use ~ you can escape with a backslash, if not you have to use #DQUOTE$

Code:
Debug  ~"[\"#a-zA-Z_ ]+"

Debug "[" + #DQUOTE$ + "#a-zA-Z_ ]+"


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: lgb-this, marc_256, StarBootics and 44 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye