Thomymaster Posted May 21, 2015 Share Posted May 21, 2015 Hi I am struggeling around with an RegExp I need to check a string, it should only contain digits and a - This is what i have so far StringRegExp($sColData,"[\s\D]",0)which returns true for every non-digit (\D) character including @CR (which should not exist as well) and whitespaces (\s], but it returns true even if the string contains a - which should return 0 How can i fix that, i want like "match any non-digits and whitespace characters except for a -" ? Best,Thomy Link to comment Share on other sites More sharing options...
mikell Posted May 21, 2015 Share Posted May 21, 2015 (edited) I need to check a string, it should only contain digits and a -$sColData = "-123" Msgbox(0,"", StringRegExp($sColData,"^[\d-]+$") )If the - is for negative ints then : StringRegExp($sColData,"^-?\d+$")If the - is for separation between 2 numbers : StringRegExp($sColData,"^\d+-?\d*$")You should be more precise concerning the requirements Edited May 21, 2015 by mikell Link to comment Share on other sites More sharing options...
Thomymaster Posted May 26, 2015 Author Share Posted May 26, 2015 (edited) Hi The "-" should not exist in the string at all (it is used to separate the 2 numbers).Further, CR LF should not exist in the string as well So the string format will be <number1>-<number2> or only <number1> Your pattern "^\d+-?\d*$" seems to detect CR/LF/CRLF everywhere in the string but not at the end (after the second number). If you could tell me a solution for this, it would be great (the number-only and "-" detection works fine) Edited May 26, 2015 by Thomymaster Link to comment Share on other sites More sharing options...
jguinch Posted May 26, 2015 Share Posted May 26, 2015 Mikell's pattern "^\d+-?\d*$" does not match any CR/LF/CRLF. \d* is for \d 0 or more times.But it could return true for 123- (with any number after the -)Try this one :StringRegExp($sColData,"^\d+(-\d+)?$") Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now