Como explicar para alguém sóbrio que o código abaixo não funciona?
O cara que escreveu o método matches(String regex) da classe String não sabia que para você matchear a string inteira você deve usar a regex: "^Oliveira$". Em todas as outras linguagens, a regex "Oliveira" significa faca o match em qualquer lugar da String. Menos em Java.
Para quem já programou em uma linguagem com suporte descente a regular expressions, vai gostar muito de conhecer o MentaRegex: http://mentaregex.soliveirajr.com/
Alguém mais ficava irritado com o suporte tosco do Java a regular expressions???
Veja como vc pode fazer com o MentaRegex:
The method matches returns a boolean saying whether we have a regex match or not.
The method match returns an array with the groups matched. So it not only tells you whether you have a match or not but it also returns the groups matched in case you have a match.
The method sub allows you perform substitutions with regex.
Support global and case-insensitive regex.
Allows you to change the escape character in case you don't like to see so many '\'.
This message was edited 3 times. Last update was at 28/09/2011 15:44:18
|