Page 1 of 1

? Need Help with Regular Expression

Posted: Sat May 04, 2024 10:25 pm
by millie78526
TIA ;
I want to weed out lines that have only numeric characters OR
numeric characters and space(s) .
If it is a numeric line , I want to 'Goto SkipThisLine'
But my RegEx lets thru every line .
How can this be fixed?

Code: Select all

;    CreateRegularExpression(0, "^[0-9 ]+$") ;  First Try "^[0-9]+$" 
     If ExamineRegularExpression(0, aLine$)
       Debug "RegularExpressionError() = " + RegularExpressionError()
;        Goto SkipThisLine      
       Debug  "SkipThisLine = " +  aLine$
     EndIf
       Debug  "This Line Not Numeric = " +  aLine$

Re: ? Need Help with Regular Expression

Posted: Sat May 04, 2024 10:57 pm
by Andesdaf
Use MatchRegularExpression() instead

Re: ? Need Help with Regular Expression

Posted: Sun May 05, 2024 6:31 am
by jacdelad
If you use ExamineRegularExpression, it will always return true, as long as the the examination can be started. You need NextRegularExpressionMatch, to find the next match. This is helpful to find the lines, when you want to match a textblock with more than one line. To weed out the numeric lines, you need to negate the RegEx and put brackets around the match to read it.
When comparing it line by line, use MatchRegularExpression, like Andesdaf said. This is a matter of speed, if you want to compare a lot of lines which come in a block (like reading a log file) I would prefer the first method, which should be faster.

Re: ? Need Help with Regular Expression

Posted: Sun May 05, 2024 2:10 pm
by AZJIO
https://www.purebasic.fr/english/viewtopic.php?t=76808
click the "Copy" button and you will get ready-made code for the regular expression

Re: ? Need Help with Regular Expression

Posted: Sun May 05, 2024 8:23 pm
by millie78526
Thank you Andesdaf , works much better:

Code: Select all

;    CreateRegularExpression(0, "^[0-9 .]+$") ; First Try "^[0-9]+$" 
    If MatchRegularExpression(0, aLine$)  
;       Debug "RegularExpressionError() = " + RegularExpressionError()
       Debug  "SkipThisLine = " +  aLine$
        Goto SkipThisLine      
     EndIf