I\'m trying to match all occurrences of strings starting with --
and ending with a single space .
The file I\'m handling is the OpenVPN manual
I think your question caused some confusion due to the use of string. You might want to look up the usage of computer science (e.g. here). What you are looking for is word, starting with --
and ending with a space (or maybe the end of the line).
You can use (?:^|(?<=\s))--\S+
here.
(?:^|(?<=\s))
check that there is a space or the start of a line in front (using a lookbehind)--\S+
match double -
and one or more non-space characters
Another possibility is (?:^|(?<=\s))--\w+(?=\s|$)
. Here it looks for a sequence of word characters (letters, digits, underscore) and by a lookahead ensures that it ends with a space or the end of the line.