Thanks to Michael Vogel :
;viewtopic.php?f=12&t=70463&hilit=NextRe ... ssionMatch
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...
RegularExpression ... IT WORKS BUT WHY ??? ;-)
RegularExpression ... IT WORKS BUT WHY ??? ;-)
Last edited by Joris on Sat Aug 01, 2020 10:47 am, edited 1 time in total.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Re: RegularExpression ... IT WORKS BUT WHY ??? ;-)
This is escape sequences. See Literal stringsJoris 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 ?
https://www.purebasic.com/documentation ... rules.html
Code: Select all
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)
Re: RegularExpression ... IT WORKS BUT WHY ??? ;-)
But why is this one then wrong ?
regex=CreateRegularExpression(#PB_Any, "[\"#a-zA-Z_ ]+")
regex=CreateRegularExpression(#PB_Any, "[\"#a-zA-Z_ ]+")
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
- NicTheQuick
- Addict
- Posts: 1227
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
Re: RegularExpression ... IT WORKS BUT WHY ??? ;-)
Because you can not use double quotes inside a string without escaping them. And therefore you need to use the syntax for escaped strings: ~""Joris wrote:But why is this one then wrong ?
regex=CreateRegularExpression(#PB_Any, "[\"#a-zA-Z_ ]+")
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.
Re: RegularExpression ... IT WORKS BUT WHY ??? ;-)
If you use ~ you can escape with a backslash, if not you have to use #DQUOTE$
Code: Select all
Debug ~"[\"#a-zA-Z_ ]+"
Debug "[" + #DQUOTE$ + "#a-zA-Z_ ]+"