public void ReplaceText() { Regex regex = GetRegEx(TextToFind); string input = editor.Text.Substring(editor.SelectionStart, editor.SelectionLength); Match match = regex.Match(input); bool replaced = false; if (match.Success && match.Index == 0 && match.Length == input.Length) { editor.DocumentReplace(editor.SelectionStart, editor.SelectionLength, TextToReplace); replaced = true; } if (!FindNextInternal() && !replaced) { SystemSounds.Beep.Play(); } }