N3lson Posted May 15, 2018 at 08:58 AM Report #610565 Posted May 15, 2018 at 08:58 AM Boas estou a tentar criar uma função que faça a substituição de strings encontradas por Regex. O que está a acontecer é que a função está a retornar apenas um grupo e a repeti-lo. Aqui tenho a função. string encontrar = @"t[a-z]{4}\d{3}"; Match resultado = Regex.Match(sql, encontrar); if(resultado.Success) { MatchCollection grupo = Regex.Matches(sql, encontrar); for(int i = 0; i < grupo.Count; i++) { sql = Regex.Replace(sql, encontrar, "t" + grupo[i] + "100"); } } return sql; Alguma ajuda, Obrigado You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.
N3lson Posted May 15, 2018 at 10:35 AM Author Report #610566 Posted May 15, 2018 at 10:35 AM Já resolvi, desta forma, podem fechar o tópico. string nsql = null; string encontrar = @"t[a-zA-Z]{4}\d{3}"; Match resultado = Regex.Match(sql, encontrar); MatchCollection grupo = Regex.Matches(sql, encontrar); foreach(Match m in grupo) { nsql = Regex.Replace(sql, encontrar, "t{$0}" + empresa, RegexOptions.Singleline); } nsql = Regex.Replace(nsql, @"{", String.Empty); nsql = Regex.Replace(nsql, @"}", String.Empty); return nsql; You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.
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