alexandre1985 Posted April 9, 2015 at 02:24 PM Report Share #580980 Posted April 9, 2015 at 02:24 PM (edited) Tenho este método: private boolean isNumeric(String str) { return str.matches("-?\\d+(\\.\\d+)?"); //match a number with optional '-' and decimal. } que verifica se a string é um numero (decimal ou inteiro negativo ou positivo) Eu quero que a expressão só verifique se o numero é um integer positivo. Como deve ficar? Edited April 9, 2015 at 02:26 PM by alexandre1985 http://alexandre1985.github.io Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted April 9, 2015 at 02:34 PM Report Share #580981 Posted April 9, 2015 at 02:34 PM o número está no meio de um texto ou é só mesmo o número ? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
Solution nelsonr Posted April 9, 2015 at 02:35 PM Solution Report Share #580982 Posted April 9, 2015 at 02:35 PM Boas, em principio deve bastar se ficar "\\d+" Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted April 9, 2015 at 02:42 PM Report Share #580983 Posted April 9, 2015 at 02:42 PM Boas, em principio deve bastar se ficar "\\d+" errado, porque isso valida algo como "-123" (ignora o caracter -) vederia ser com o negative lookbehind como : "(?<!\-)\\d+" IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
alexandre1985 Posted April 9, 2015 at 02:45 PM Author Report Share #580984 Posted April 9, 2015 at 02:45 PM Boas, em principio deve bastar se ficar "\\d+" Está perfeito! OS numeros negativos ou decimais dão false 🙂 http://alexandre1985.github.io 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