Solved

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

Posted on 2013-01-28
8
333 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
This article will help you understand what HashTables are and how to use them in PowerShell.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

821 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