1
I’m picking up a bit here with to assemble the Regex of a pattern I set up, which would be this:
ALTERAC[AO,OES] [DE] CADASTRO[S] [-] SOCIAL
What is between [ ]
is what may vary. The doubt is that in the words "OF" and "-" may or may not have, so I wanted to ignore them. I have tried several ways but it is not going as necessary.
Here’s the code I put together:
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
string texto = "alteracao de cadastro social";
//string texto = "alteracao de cadastro - social";
//string texto = "alteracoes de cadastro social";
//string texto = "alteracao cadastro social";
//string texto = "alteracao cadastro - social";
bool passou = (new Regex(@"(a)(l)(t)(e)(r)(a)(c)(ao|oes)( )(de)( )(c)(a)(d)(a)(s)(t)(r)(o|os)( )(-)(s)(o)(c)(i)(a)(l)").IsMatch(texto));
Console.WriteLine(passou);
}
}
Try using the quantifier
?
, which corresponds to zero or once. See this reference– danieltakeshi
I tried putting (in the case of "of") (of?) but is not ignoring
– aa_sp
Try
(de)?
. Behold this reference with examples to better understand each Regex element– danieltakeshi
It doesn’t work! I’m more than 1 day trying everything that is way and this I’m not getting to finish. just ignore the word and the - (but n can use replace)
– aa_sp