Validation Expression in ASP.NET

xiaoxiao2021-03-06  21

Character Classes

Character classes are a mini-language within regular expressions, defined by the enclosing hard braces []. The simplest character class is simply a list of characters within these braces, such as [aeiou]. When used in an expression, any one of these Characters Can Be Used At this Position In The Pattern (But Only One Unless). It's Important To Note That Character Classes Cannot Be Used To Define Words Or Patterns, ONLY SINGLE CHARACTERS.

. To specify any numeric digit, the character class [0123456789] could be used However, since this would quickly get cumbersome, ranges of characters can be defined within the braces by using the hyphen character, -. The hyphen character has special meaning within character classes, not within regular expressions (thus it does not qualify as a regular expression metacharacter, exactly), and it only has special meaning within a character class if it is not the first character. To specify any numeric digit using a hyphen, you Would Use [0-9]. Similarly for any LowerCase Letter, You Could Use [AZ], or for any Uppercase Letter [AZ]. The Range Defined by The Hyphen Depends on The Character Set Being Used, So The Order In Which T characters occur in the (for example) ASCII or Unicode table determines which characters are included in the range If you need a hyphen to be included in your range, specify it as the first character for example,.. [-.?] would match Any One of Those Four Characte rs (note the last character is a space). Also note, the regular expression metacharacters are not treated special within character classes, so they do not need escaped. Consider character classes to be a separate language from the rest of the regular expression world, With their own rules and syntax.

You can also match any character except a member of a character class by negating the class using the carat ^ as the first character in the character class. Thus, to match any non-vowel character, you could use a character class of [^ aAeEiIoOuU ]. Note That if you want to negate a HYPHEN, IT SHOULD BE The Second Character in The Character Class, AS in [^ -]. Remetr That the ^ HAS a Totally Different Meaning Withnin a Totally Class Than IT Has At the Start of A Regular Expression Pattern.some Examples of Character Classes in Action Are Listed Below.

PatternInputs (Matches) ^ B [Aeiou] T $ BAT, BET, BIT, BOT, But ^ [0-9] {5} $ 11111, 12345, 99999 ^ C: // C: / Windows, C: /, C: /FOO.TXT, C: / FOLLOWED by Anything elseabc $ ABC, 123ABC, Any String ending with abc (abc) {2,3} Abcabc, abcabcab ^ [^ -] [0-9] $ 0, 1, 2, ... (Will NOT MATCH -0, -1, -2, ETC.)

转载请注明原文地址:https://www.9cbs.com/read-43406.html

New Post(0)