Use Regular Expressions in NPS
Applies To: Windows Server 2016
This topic explains the use of regular expressions for pattern matching in NPS in Windows Server 2016. You can use this syntax to specify the conditions of network policy attributes and RADIUS realms.
You can use the following table as a reference source when creating regular expressions with pattern-matching syntax.
|Marks the next character as a character to match.|
|Matches the beginning of the input or line.|
|Matches the end of the input or line.|
|Matches the preceding character zero or more times.|
|Matches the preceding character one or more times.|
|Matches the preceding character zero or one times.|
|Matches any single character except a newline character.|
|Matches "pattern" and remembers the match.|
|`x||y `||Matches either x or y.|
|Matches exactly n times (n is a non-negative integer).|
|Matches at least n times (n is a non-negative integer).|
|Matches at least n and at most m times (m and n are non-negative integers).|
|Matches any one of the enclosed characters (a character set).|
|Matches any characters that are not enclosed (a negative character set).|
|Matches a word boundary (for example, a space).|
|Matches a nonword boundary.|
|Matches a digit character (equivalent to digits from 0 to 9).|
|Matches a nondigit character (equivalent to |
|Matches a form feed character.|
|Matches a line feed character.|
|Matches a carriage return character.|
|Matches any white space character including space, tab, and form feed (equivalent to |
|Matches any non-white space character (equivalent to |
|Matches a tab character.|
|Matches a vertical tab character.|
|Matches any word character, including underscore (equivalent to |
|Matches any non-word character, excluding underscore (equivalent to |
|Refers to remembered matches (|
|Allows the insertion of ASCII codes into regular expressions (|
Examples for network policy attributes
The following examples describe the use of the pattern-matching syntax to specify network policy attributes:
To specify all phone numbers within the 899 area code, the syntax is:
To specify a range of IP addresses that begin with 192.168.1, the syntax is:
Examples for manipulation of the realm name in the User Name attribute
The following examples describe the use of the pattern-matching syntax to manipulate realm names for the User Name attribute, which is located on the Attribute tab in the properties of a connection request policy.
To remove the realm portion of the User Name attribute
In an outsourced dial-up scenario in which an Internet service provider (ISP) routes connection requests to an organization NPS server, the ISP RADIUS proxy might require a realm name to route the authentication request. However, the NPS server might not recognize the realm name portion of the user name. Therefore, the realm name must be removed by the ISP RADIUS proxy before it is forwarded to the organization NPS server.
To replace firstname.lastname@example.org with *example.microsoft.com\user*
To replace domain\user with *specific_domain\user*
To replace user with *user@specific_domain*
Example for RADIUS message forwarding by a proxy server
You can create routing rules that forward RADIUS messages with a specified realm name to a set of RADIUS servers when NPS is used as a RADIUS proxy. Following is a recommended syntax for routing requests based on realm name.
- NetBIOS name:
In the following example, wcoast.microsoft.com is a unique user principal name (UPN) suffix for the DNS or Active Directory domain wcoast.microsoft.com. Using the supplied pattern, the NPS proxy can route messages based on domain NetBIOS name or UPN suffix.
- NetBIOS name:
- UPN suffix:
For more information about managing NPS, see Manage Network Policy Server.
For more information about NPS, see Network Policy Server (NPS).