0

I am using power-shell and am getting the below output from my program.

I am having problems getting the password from the mess of other things. Ideally i need to get Hiva!!66 by itself. I am using reg-ex to accomplish this and its just not working. the password will always be 8 characters have an upper and a lowercase and a special character. I have created the split and everything else i need but the reg-ex part is messing with me.

I am away that there are a lot of questions around reg-ex and passwords but those don't seem to have a lot of mess before and after it.Any help would be appreciated. My best attempt so far is:

"(?=.*\d)(?=.*[A-Z])(?=.*[!@#\$%\^&\*\~()_\+\-={}\[\]\\:;`"'<>,./]).{8}$"

C:\Users\<username>\AppData\Roaming\Crystal Point\OutsideView\Macro\CONNECTEXP.VCB:5:For intTmp = 1 To 4
C:\Users\<username>\AppData\Roaming\Crystal Point\OutsideView\Macro\CONNECTEXP.VCB:8:cboCOMPort.SelectString 1, "1"
C:\Users\<username>\AppData\Roaming\Crystal Point\OutsideView\Macro\CONNECTEXP.VCB:11:str2CRLF = Chr(13) & Chr(10) & Chr(13) & Chr(10)
C:\Users\<username>\AppData\Roaming\Crystal Point\OutsideView\Macro\CONNECTEXP.VCB:14:    & "include emulation type (currently Tandem), the I/O method (currently Async) and host connection information 
for the session (currently COM9, 8N1)" _
C:\Users\<username>\AppData\Roaming\Crystal Point\OutsideView\Macro\CONNECTEXP.VCB:15:    & " to the correct values for your target host (e.g., TCP/IP and host IP name or address) and save the 
IOSet "CHARSIZE", "8"
PASS="Hiva!!66" If DDEAppReturnCode() <> 0 Then
If DDEAppReturnCode() <> 0 Then
C:\Users\<username>\AppData\Roaming\Crystal Point\OutsideView\Macro\DDEtoXL.vcb:28:    MsgBox "Could not load " & txtWorkSheet.text, 48
C:\Users\<username>\AppData\Roaming\Crystal Point\OutsideView\Macro\DDEtoXL.vcb:37:DDESheetChan = -1
C:\Users\<username>\AppData\Roaming\Crystal Point\OutsideView\Macro\DDEtoXL.vcb:38:DDESystemChan = -2
4

4 回答 4

0

Did you try the following regex:

^PASS="(.{8})"

?

于 2013-08-19T06:38:53.803 回答
0

Just use this

(?<=PASS=").+(?=")
于 2013-08-19T06:43:12.273 回答
0

You can extract the password from that output with something like this:

... | ? { $_ -cmatch 'PASS="(.{8})"' | % { $matches[1] }

or like this (in PowerShell v3):

... | Select-String -Case 'PASS="(.{8})"' | % { $_.Matches.Groups[1].Value }

In PowerShell v2 you'll have to do something like this if you want to use Select-String:

... | Select-String -Case 'PASS="(.{8})"' | select -Expand Matches |
   select -Expand Groups | select -Last 1 | % { $_.Value }
于 2013-08-19T12:23:40.830 回答
0

If you can't count on the quotes or the PASS= being there, you'll have to rely on the password's composition to do everything. The following regex matches a string of eight consecutive characters of the allowed types, with the lookahead and lookbehind to make sure there aren't more than eight.

$regex = [regex] @'
(?x)
(?<![!@#$%^&*~()_+\-={}\[\]\\:;`<>,./A-Za-z0-9])
(?:
  [!@#$%^&*~()_+\-={}\[\]\\:;`<>,./]()
  |
  [A-Z]()
  |
  [a-z]()
  |
  [0-9]()
){8}
\1\2\3\4
(?![!@#$%^&*~()_+\-={}\[\]\\:;`<>,./A-Za-z0-9])
'@

It also verifies that there's at least one of each character type: uppercase letter, lowercase letter, digit and special. The lookahead approach used in your regex won't work because it can look too far ahead, beyond the end of the word you're trying to match. Instead, I put an empty group in each branch to act like check boxes. If a backreference to one of those groups fails, it means that branch didn't participate in the match, meaning in turn that the associated character type was not present.

于 2013-08-19T15:38:41.480 回答