Matching String in Text File Lines

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MusoCity
Posts: 95
Joined: 24 Mar 2018, 20:45

Matching String in Text File Lines

06 Sep 2023, 07:38

I have a text file that has lines of paths
C:\Docs\nine\nine^01"some text to end of line"
C:\Docs\nine\nine^02"some text to end of line"
C:\Docs\seven\seven^1"some text to end of line"
C:\Docs\seven\seven^2"some text to end of line"

so if I have a needle "seven^" and it has 1 or two digits after it, I want those and the rest of the line

I want to add each instance to a new line in a string:
nine^01some text
nine^01some text
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Matching String in Text File Lines

10 Sep 2023, 05:50

Code: Select all

#Requires AutoHotkey v1.1.33
filePath := A_ScriptDir "\test.txt"
str      := ""
If FileExist(filePath)
 Loop Read, % filePath
  RegExMatch(A_LoopReadLine, ".*\\\K.+\^\d{1,2}.*", m) && str .= (str = "" ? "" : "`n") m
Else MsgBox 48, Error, % "File not found.`n`n" filePath
MsgBox 64, Result, % str

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mstrauss2021, william_ahk and 366 guests