Paxdiablo and tanascius' answers correctly explain why your regex fails to compile.
But:
You need to be careful with your regex, even after escaping the parenthesis: \b
only matches at word boundaries (a word being constructed from characters of the \w
shortcut - letters, digits, and underscore), not after punctuation like parentheses. In your case the regex will not match in a string like foo Serial) bar
. It will match in foo Serial)bar
, but only because the \b
matches before bar
. Likewise, it won't match the string Serial)
.
So, simply surrounding a string with \b
s will not always do what you seem to be expecting it to do.
Edit: If, according to your comment below, in the following list...
foo Serial) bar
foo (Serial) bar
foo Serial). bar
foo Serial))))))
foo Serial)
...only the first and fifth should match, I'm inferring that the rule is to match a whole word only if it is preceded/followed by whitespace or start/end of string.
In that case, use
If Regex.IsMatch(Output, "(?<=^|\s)" & Regex.Escape("Serial)") & "(?=\s|$)") Then
However, this will now no longer match foo
in This is foo.
or He said "foo"
. If you want to allow this, use
If Regex.IsMatch(Output, "(?<=^|\b|\s)" & Regex.Escape("Serial)") & "(?=\s|\b|$)") Then
...but this will now also match the second example. Choose your weapon carefully :)
(Explanation: (?<=^|\b|\s)
is a positive lookbehind assertion that matches if it is possible to match either the start of the string, a word boundary, or a whitespace character right before the current position, without adding anything to the match result. (?=\s|\b|$)
is its lookahead counterpart.)