Parse passwords from line of text - multiple hits - regex Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
coder_chick
Posts: 221
Joined: 05 Nov 2015, 10:43

Parse passwords from line of text - multiple hits - regex

Post by coder_chick » 05 Aug 2020, 14:33

I have a file that has one line containing a bunch of HTML code. I want to parse all the passwords and append them to a text log (one pw per line). Basically, I need everything in between data-tid="foundPassword"> and the next instance of </span> for each instance on the same line.

LINE1:&nbsp;&nbsp;&nbsp;</span><span>data-tid="foundPassword">password1</span></span></span>&nbsp;&nbsp;&nbsp;</span><span class="globalReport_infoStringAlongPassword">>&nbsp;&nbsp;&nbsp;</span><span>data-tid="foundPassword">password2</span>

I'm sure this is an easy Regex solution, but I really struggle with regex and am trying to learn, so any example you can provide will be super helpful. Note: The passwords could be complex, so don't assume its just alpha numeric as in my examples above. Also note, the actual line of text contains hundreds of passwords.
♥ ❤ ❥ coder_chick ♥ ❤ ❥

User avatar
TheDewd
Posts: 1446
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Parse passwords from line of text - multiple hits - regex  Topic is solved

Post by TheDewd » 05 Aug 2020, 14:52

Code: Select all

#SingleInstance, Force

String = "&nbsp;&nbsp;&nbsp;</span><span>data-tid="foundPassword">password1</span></span></span>&nbsp;&nbsp;&nbsp;</span><span class="globalReport_infoStringAlongPassword">>&nbsp;&nbsp;&nbsp;</span><span>data-tid="foundPassword">password2</span>"

Pos := 0

While (Pos := RegExMatch(String, "<span>data-tid=""foundPassword"">(.*?)<\/span>", Match, Pos + 1)) {
	FileAppend, % Match1 "`n", PasswordLog.txt
}
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.

User avatar
coder_chick
Posts: 221
Joined: 05 Nov 2015, 10:43

Re: Parse passwords from line of text - multiple hits - regex

Post by coder_chick » 05 Aug 2020, 14:58

Yup, that'll do it. Thank you.
♥ ❤ ❥ coder_chick ♥ ❤ ❥

teadrinker
Posts: 1900
Joined: 29 Mar 2015, 09:41
Contact:

Re: Parse passwords from line of text - multiple hits - regex

Post by teadrinker » 05 Aug 2020, 15:26

Code: Select all

html = &nbsp;&nbsp;&nbsp;</span><span>data-tid="foundPassword">password1</span></span></span>&nbsp;&nbsp;&nbsp;</span><span class="globalReport_infoStringAlongPassword">>&nbsp;&nbsp;&nbsp;</span><span>data-tid="foundPassword">password2</span>

MsgBox, % Trim( RegExReplace(html, "s).*?((?<=data-tid=""foundPassword"">)[^<]+)|.*", "$1`n"), "`n" )

Post Reply

Return to “Ask For Help”