1
I want to make patterns that way:
[a-z]+[acentos] || [a-z]+[acentos]+[espaço]+[a-z]+[acentos] || [a-z]+[acentos]+[-]+[a-z]+[acentos]
In order to be able to register a word, it is necessary to be within one of these standards.
For example:
téstê || téstê téstê || téstê-téstê
I did so:
palavra = TextBox1.Text;
Regex regex;
string padrao = @"[^A-Za-záàâãéêíîóõôúûçÁÀÂÃÉÈÍÓÔÕÚÇ']";
regex = new Regex(padrao);
string palavra2 = regex.Replace(palavra, "");
if (palavra == palavra2)
{
Label1.Text = "Ok!";
}
else {
padrao = @"[^A-Za-záàâãéêíîóõôúûçÁÀÂÃÉÈÍÓÔÕÚÇ'] [^A-Za-záàâãéêíîóõôúûçÁÀÂÃÉÈÍÓÔÕÚÇ']";
regex = new Regex(padrao);
palavra2 = regex.Replace(palavra, "");
if (palavra == palavra2)
{
Label1.Text = "Ok!";
}
}
The first pattern worked because everything that is not letter or letter with accent is replaced by empty. I store this exchange in a new string and compare it to the previous one, if they are the same, the word followed the pattern. If the first string had a number for example, the new string (which is the default) would be without the number, so the word did not follow the pattern.
The problem is in the other patterns. I took the test and this:
@"[^A-Za-záàâãéêíîóõôúûçÁÀÂÃÉÈÍÓÔÕÚÇ'] [^A-Za-záàâãéêíîóõôúûçÁÀÂÃÉÈÍÓÔÕÚÇ']";
You are agreeing to start with space. But you should change the space that is in the beginning to void. Space should only be allowed in the middle. I don’t know how to use these expressions. I believe someone who knows, will be able to tell me how to leave my expression.
If it was PHP you could do thus, but from what I’ve seen, C# doesn’t have a good Unicode support.
– Guilherme Lautert