1

I'm refactoring this regular expression C# string into a constant and I'm not sure how best to name it (my regex fu is weak).

@"^(?!\s\s)"

Doesn't the question mark denote something that's optional? What is the question saying is optional?

I've found that, as a developer, you have to clearly understand something before you can properly name it (also: Naming is Hard), so I want to clearly understand this and then give it a proper name.

What is the name of this regular expression?

I'm considering LinesThatDoNotStartWithTwoSpaces or DoesNotStartWithTwoSpaces.

4

3 回答 3

5

The construct itself is a Negative lookahead. It specifies a group that can not match after your main expression.

In this case, yes, it matches when the line being matched does not start with two spaces (white spaces ).

I would name the regex as NotMatchLineStartingWithTwoWhiteSpaces

于 2012-04-11T12:14:26.550 回答
1

I always trying to use Not in variable name. For example NotHuman, its meaning will change with the definition of Human. Also, variable name should tells what-this-is but not what-this-can-do, so I think it's not a good idea to use verb in variable name, such as Search, Match.

For your case, how about LineWithoutIndentation, similar to the property text-indent in CSS3.

于 2012-04-12T04:17:16.553 回答
0

It's called Negative lookahead

于 2012-04-11T12:12:50.960 回答