views:

54

answers:

1

Could anyone explain what's being replaced here?

I don't know if enough information is present to understand what's being searched and what's being replaced:

    regEx.Pattern = "(\s) *(\S)"
    regEx.Global = True
    that = regEx.Replace(that, "$1$2")
+6  A: 

\s is a whitespace character, such as a tab or a space. \S is any other character. So this preserves the first whitespace character and strips out all following spaces (specifically spaces, not any whitespace character) that occur before a printing character. I'm guessing maybe it's to "clean" lines that use both tab and space indentation, though this seems like a pretty lousy way to do that.

Chuck
Thanks. Does the "$1$2" syntax refer to arguments that are supposed to be coming from somewhere else in the program?
Hugo
`\s` also matches `\n` and `\r` and probably other whitespace characters (like vertical tab).
eyelidlessness
Hugo, $1 and so on refer to capturing groups in the regex. In this case, (\s) is $1, and (\S) is $2.
eyelidlessness