?
Solved

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

Posted on 2013-01-28
8
Medium Priority
?
339 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 11

Accepted Solution

by:
ScriptAddict earned 336 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 336 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 13

Assisted Solution

by:Jeff Darling
Jeff Darling earned 664 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 332 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 13

Assisted Solution

by:Jeff Darling
Jeff Darling earned 664 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 332 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

777 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