oi. gostaria muito de saber porque usa esse trecho de códiog? para que ele serve? matcher.replaceFirst("$1");
Dúvida basica sobre REGEX - expressao regular
M
1 Resposta
Boa Tarde!
Estou colocando o link da documentação de java, é bem fácil e rápido procurar alguma coisa quando se tem uma dúvida em relação a algum método ou o que ele faz.
http://docs.oracle.com/javase/6/docs/api/
Segue o trecho que diz a respeito do replaceFirst:
replaceFirst
public String replaceFirst(String regex,
String replacement)
Replaces the first substring of this string that matches the given regular expression with the given replacement.
An invocation of this method of the form str.replaceFirst(regex, repl) yields exactly the same result as the expression
Pattern.compile(regex).matcher(str).replaceFirst(repl)
Note that backslashes (\) and dollar signs ($) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string; see Matcher.replaceFirst(java.lang.String). Use Matcher.quoteReplacement(java.lang.String) to suppress the special meaning of these characters, if desired.
Parameters:
regex - the regular expression to which this string is to be matched
replacement - the string to be substituted for the first match
Returns:
The resulting String
Throws:
PatternSyntaxException - if the regular expression's syntax is invalid
Since:
1.4
See Also:
Pattern
Criado 17 de janeiro de 2013
Ultima resposta 24 de jan. de 2013
Respostas 1
Participantes 2
Alura O que é Python? — um guia completo para iniciar nessa linguagem de programação Acesse agora o guia sobre Python e inicie sua jornada nessa linguagem de programação: o que é e para que serve, sua sintaxe e como iniciar nela!
Casa do Codigo Engenharia de Prompt para Devs: Um guia para aprender a... Por Ricardo Pupo Larguesa — Casa do Codigo