I need to detect missing consonants in a word where they are supposed to be doubled but one is missing. Example: inovation instead of innovation. I tried my best to come up with a variant and so far could not succeed. Things like (^nn^n) don t match at all. What I've done so far is this
Regex reg=new Regex ( "(c{1,})|(g{1,})|(l{1,})|(n{1,})|(p{1,})|(s{1,})" );
MatchCollection col=reg.Matches ( word );
It catches at least one character or perhaps more but then I sort them out in a foreach loop. The ones that are truly doubled are skipped (Length>= 2).
I am wondering if there is a more efficient way to do it Thanks.
AlexBB - Vista Ult64 SqlSer64 WinSer64
How about this one:
@"(?<c>[cglnps])(?!\k<c>)(?<!\k<c>\k<c>)"
Philippe Leybaert
I don't quite understand your question, but I'll try to make a guess:
(?<c>[cglnps])(?!\k<c>)
This will match any c,g,l,n,p or s which is not doubled.
Philippe Leybaert
Philippe Leybaert wrote:
I don't quite understand your question, but I'll try to make a guess:
(?<c>[cglnps])(?!\k<c>)
This will match any c,g,l,n,p or s which is not doubled.
Thanks, I think you did understand my question but your regex failed. It captured (matched) the first "n" in "connectio"
It is not supposed to do it. Only if "n" were single the match should have taken place.
AlexBB - Vista Ult64 SqlSer64 WinSer64
How about this one:
@"(?<c>[cglnps])(?!\k<c>)(?<!\k<c>\k<c>)"
Philippe Leybaert
Philippe Leybaert wrote:
How about this one:
@"(?<c>[cglnps])(?!\k<c>)(?<!\k<c>\k<c>)"
Yep, this one seems to be perfect. You are a magician. I marked your answer as the one that solved the problem.