[SOLVED] Regular expression excluding spaces
Posted: Wed Jul 17, 2024 11:23 pm
Hello,
It's late at night where I live, and maybe I no longer have eyes facing the holes, but I don't understand the results returned by PB's RegEx instructions.
Normally I'd only get "words" that are separated by spaces, but that's not the case. Spaces are returned too as an empty string!???
There must be something that escapes my reasoning...
It's late at night where I live, and maybe I no longer have eyes facing the holes, but I don't understand the results returned by PB's RegEx instructions.
Normally I'd only get "words" that are separated by spaces, but that's not the case. Spaces are returned too as an empty string!???
There must be something that escapes my reasoning...
Code: Select all
String.s="This is example of string that contains spaces"
;If CreateRegularExpression(0,"[^"+Chr(32)+Chr(255)+"]*") ; Chr(32)+Chr(255)=" " : Doesn't works under PB too!???
If CreateRegularExpression(0,"(\S)*") ; \S = any non white-space character
If ExamineRegularExpression(0,String)
While NextRegularExpressionMatch(0)
Debug "Position: "+RegularExpressionMatchPosition(0)+" "+"String: |"+RegularExpressionMatchString(0)+"|"
Wend
EndIf
FreeRegularExpression(0)
EndIf
Debug "*******"
Debug "*******"
Debug "Example with #PB_RegularExpression_Extended"
String="This is another example of string that contains spaces"
If CreateRegularExpression(0,"(\S)*",#PB_RegularExpression_Extended)
If ExamineRegularExpression(0,String)
While NextRegularExpressionMatch(0)
Debug " Position: "+RegularExpressionMatchPosition(0)+" "+"String: |"+RegularExpressionMatchString(0)+"|"
Wend
EndIf
FreeRegularExpression(0)
EndIf
Thanks for your ligths.DebugOutput window wrote: Position: 1 String: |This|
Position: 5 String: ||
Position: 6 String: |is|
Position: 8 String: ||
Position: 9 String: |example|
Position: 16 String: ||
Position: 17 String: |of|
Position: 19 String: ||
Position: 20 String: |string|
Position: 26 String: ||
Position: 27 String: |that|
Position: 31 String: ||
Position: 32 String: |contains|
Position: 40 String: ||
Position: 41 String: |spaces|
*******
*******
Example with #PB_RegularExpression_Extended
Position: 1 String: |This|
Position: 5 String: ||
Position: 6 String: |is|
Position: 8 String: ||
Position: 9 String: |example|
Position: 16 String: ||
Position: 17 String: |of|
Position: 19 String: ||
Position: 20 String: |string|
Position: 26 String: ||
Position: 27 String: |that|
Position: 31 String: ||
Position: 32 String: |contains|
Position: 40 String: ||
Position: 41 String: |spaces|