Solved

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

Posted on 2013-01-28
8
330 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 68

Assisted Solution

by:Qlemo
Qlemo earned 83 total points
Comment Utility
[\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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 12

Assisted Solution

by:Jeff Darling
Jeff Darling earned 166 total points
Comment Utility
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
Comment Utility
[\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
Comment Utility
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 21

Author Closing Comment

by:Joseph Moody
Comment Utility
Thank you all so much!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Why would I want to create a function for tracking messages? I am glad you asked. As with most monotonous/routine tasks, human error tends to creep in after doing the same task over and over again. By creating a function, you load the function once…
Synchronize a new Active Directory domain with an existing Office 365 tenant
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now