Friends,
I am using PowerShell.
I am trying to write a regex match pattern for a string that has ALL these qualifications:
1. Must have one and only one period in the string.
A. At least one Alpha, A-Za-z before the period.
B. At least one Alpha, A-Z Za-z after the period.
2. The last character in the string must be numeric, 0-9 No Alpha, A-Za-z
3. The second-to-the-last character must be one of these two:
A. May be Alpha, , A-Z Za-z or
B. May be numeric, 0-9
4. No Numerics, 0-9 Allowed except the last two characters in the string.
Examples of good ones:
Joe.Jones1
Joe.Jones01
J.J1
j.j99
jo.jn01
jo.j1
I have written many small pieces of code that could be pieced together using -AND for many matches but surely there is a way to make some one-liner that can incorporate all of these.
I may be able to do it using -AND like this:
$test -notmatch “[0-9]” -AND $test -NOTmatch “[\.]" -AND $test -match “[a-zA-Z]" -AND $test -NOTmatch “[@#$%^&*()]"
But I would like to be eloquent and do something like this:
$GoodPatternCheck = $PossibleGoodName -match '.+,.+,.+,.+'
If ( $GoodPatternCheck )
I have written many short matches in my learning process which I plan on sharing with my co-workers who are also novices.
I don't see any way to attach a file here, so here is an example of the kinds of short piece of code I write and test to help me learn:
$test = "Now......... is t.he, tim,e"
Write-Host ‘$test’ $test
$Count = ($test.Split('\.')).count -1
Write-Host ‘$test’ $test
Write-Host ‘$Count’ $Count
Thank you in advance for your help on this.
I am using PowerShell.
I am trying to write a regex match pattern for a string that has ALL these qualifications:
1. Must have one and only one period in the string.
A. At least one Alpha, A-Za-z before the period.
B. At least one Alpha, A-Z Za-z after the period.
2. The last character in the string must be numeric, 0-9 No Alpha, A-Za-z
3. The second-to-the-last character must be one of these two:
A. May be Alpha, , A-Z Za-z or
B. May be numeric, 0-9
4. No Numerics, 0-9 Allowed except the last two characters in the string.
Examples of good ones:
Joe.Jones1
Joe.Jones01
J.J1
j.j99
jo.jn01
jo.j1
I have written many small pieces of code that could be pieced together using -AND for many matches but surely there is a way to make some one-liner that can incorporate all of these.
I may be able to do it using -AND like this:
$test -notmatch “[0-9]” -AND $test -NOTmatch “[\.]" -AND $test -match “[a-zA-Z]" -AND $test -NOTmatch “[@#$%^&*()]"
But I would like to be eloquent and do something like this:
$GoodPatternCheck = $PossibleGoodName -match '.+,.+,.+,.+'
If ( $GoodPatternCheck )
I have written many short matches in my learning process which I plan on sharing with my co-workers who are also novices.
I don't see any way to attach a file here, so here is an example of the kinds of short piece of code I write and test to help me learn:
$test = "Now......... is t.he, tim,e"
Write-Host ‘$test’ $test
$Count = ($test.Split('\.')).count -1
Write-Host ‘$test’ $test
Write-Host ‘$Count’ $Count
Thank you in advance for your help on this.