Solved

What does [\d\.]+$ mean?

Posted on 2013-01-28
8
334 Views
Last Modified: 2013-01-29
I have this script:

Add-PSSnapin Quest.ActiveRoles.ADManagement

$User=Read-Host "Search for a User by: First, Last, or UserName"

Get-QADUser $User | Format-Table Name, UserPrincipalName,PasswordAge,PasswordLastSet,PasswordExpires,AccountisLockedOut -AutoSize

function isNumeric ($User) {
    try {
        0 + $User | Out-Null
        return $true
    } catch {
        return $false
    }
}

if ($user -match "[\d\.]+$"){
Set-QADUser $User -UserPassword password11 -WhatIf
Unlock-QADUser $User -WhatIf
}

else {
$UserPrincipalName= Read-Host "What is the user's Pin number?"
Set-QADUser $UserPrincipalName -UserPassword test-WhatIf
Unlock-QADUser $UserPrincipalName -WhatIf
}

Open in new window


And I wanted to check if the user input is a number. I found "[\d\.]+$" on another site as a way of checking this. That code works but I have no idea what it means.

Can someone explain this? I am sorry if this is a stupid question...
0
Comment
Question by:Joseph Moody
8 Comments
 
LVL 11

Accepted Solution

by:
ScriptAddict earned 84 total points
ID: 38828126
That looks like a regular expression to me.  

http://www.regular-expressions.info/
0
 
LVL 16

Assisted Solution

by:kmslogic
kmslogic earned 84 total points
ID: 38828145
It's a regular expression.  The part in square brackets is a portion of the pattern which means match a single digit [\d.]  and the + after that means that pattern can repeat any number of times.  The $ at the end represents the end of line.
0
 
LVL 12

Assisted Solution

by:Jeff Darling
Jeff Darling earned 166 total points
ID: 38828160
That is a regular expression that matches when the value is a number or a period.

you can try it out here.

put in the expression and the sample value and click the match button to see it in action.
try putting in something other than a number or a period and you will see that it does not match.

http://www.cis.upenn.edu/~matuszek/General/RegexTester/regex-tester.html

example

sample
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 69

Assisted Solution

by:Qlemo
Qlemo earned 83 total points
ID: 38828183
[\d.] is NOT "match a single digit". The regexp is not correct, it checks for at least one digit or dot at the end of the line. Matches are e.g.
   abc123
   abc1.2
   abc.
You probably want to check for digits only. That would be '^\d+$' then.
0
 
LVL 12

Assisted Solution

by:Jeff Darling
Jeff Darling earned 166 total points
ID: 38828207
If you want to enforce a length limit, here is one way to do that.

^\d{4}$

This will only match if there is exactly 4 digits and only digits.
0
 
LVL 2

Assisted Solution

by:bcruse32347
bcruse32347 earned 83 total points
ID: 38828214
[\d\.]+$ mean?

regular expression (pattern match). Sometimes reffered to as Regexp

The "[  ]" house the pattern
The "\" tells the expression thatthe next input is a part of the pattern
The "d" is for a single digit
The "\" tells the expression thatthe next input is a part of the pattern
The "." is  a period in the expression
The "+" tells the expression the previous pattern can repeat any number of times
The "$" tells the expression it is the ens of the line
0
 
LVL 16

Expert Comment

by:kmslogic
ID: 38828230
Yeah I missed the \. and thought it was just a period which matches any character. Qlemo is definitely right and his replacement pattern is much better if the usernames you are looking for are digits only.
0
 
LVL 22

Author Closing Comment

by:Joseph Moody
ID: 38830919
Thank you all so much!
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question