Solved

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

Posted on 2013-01-28
8
336 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 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 13

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
Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

 
LVL 70

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 13

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

724 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