0

The other day I was going through the article on URL rewriting and I saw this expression

<conditions>
  <add input="{HTTP_HOST}" type=”Pattern” pattern="^([^.]+)\.mysite\.com$"> <!-- condition back-reference is captured here -->
 </conditions>

I understand all except what does the expression ([^.]+) mean. I understand ^ means beginning and . means anything but what does the whole expression mean?

4

5 回答 5

2

[^.] means "any character but a dot". (In character classes, the ^ at the beginning means "not".) The dot has no meaning inside a character class other than "a dot".

the + means "one or more".

And the parentheses group the stuff inside them, and tell the regex engine to remember what it found there.

End result being, the whole expression would match something like "sub.mysite.com", and the parenthesized part would match "sub" and remember it (presumably for future use).

于 2012-04-21T12:20:21.637 回答
1

A greedy, captured match of one or more characters that aren't . (literally; within square brackets, . really means ., not 'any character').

于 2012-04-21T12:16:58.360 回答
1

^ inside square brackets is not the beginning of input anchor, but rather reverses what the character class matches. So [^x] would match "anything except x".

Therefore, [^.] matches one or more occurrences of everything except the dot.

于 2012-04-21T12:17:10.223 回答
1
[^.]+

Means: Any character except for the dot, for one time or more, repeatedly.

"[...]" define a set of characters, that any of which satisfy.

"^" at the start of brackets mean that the set of characters are to be excluded, and all other characters are to be included. The ^ does not count as a character here.

"+" means it must at least once, and can appear more than once

"." in this case means a simple dot

于 2012-04-21T12:17:29.563 回答
1

Square brackets mean "any of the enclosed characters." A caret as the first character within square brackets changes its meaning to "none of the following characters," and a period loses its special meaning. A plus means "one or more of the previous units" and parens mean "treat the contents as a single unit."

So ([^.]+) means "One or more characters that are not periods, treated as a single unit."

于 2012-04-21T12:18:48.147 回答