Something like UNIX grep functionality (but not grep.ahk)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
thenomad
Posts: 48
Joined: 13 Jun 2016, 14:56

Something like UNIX grep functionality (but not grep.ahk)

21 Apr 2018, 18:25

I am sure this has been asked a many, many times here but my searches is not returning the result I need

I have a web page, which is dynamically created and source code doesn't contain the words I am looking for.

I need to find one line out of this page containing a keyword which is "List", but at the same time "Listed" "Listing" and "Lists" should be acceptable. So I am searching for the line with word "List" in it and assign it to a variable for further processing.

So far my script looks like this:

Code: Select all

^+w::
sleep 1000
mousemove 350,350  ; blank space on all poages
sleep 50 
mouseclick,L
sleep 50
send ^a
sleep 50
send ^c
clipwait
text=%clipboard%
needle=List
RegExMatch(text, needle, out)
msgbox %out%
return
I was hoping variable out to contain all of the line containing word List but it is only assigned to the word "List" itself, nothing else.
Where am I going wrong ? I am pretty sure my regex is to blame but I am not very familiar with regex use in AHK
User avatar
sooyke
Posts: 7
Joined: 21 Apr 2018, 10:23

Re: Something like UNIX grep functionality (but not grep.ahk)

22 Apr 2018, 01:12

Code: Select all

data=
(
first line
my experiance as a medievaList.
some more lines
ending lines
)

clipboard:=data

regexmatch(clipboard,"`am)^.*List.*$",out)
msgbox %   out
User avatar
thenomad
Posts: 48
Joined: 13 Jun 2016, 14:56

Re: Something like UNIX grep functionality (but not grep.ahk)

22 Apr 2018, 02:30

Thanks for the answer but I just realized the lines with keyword List became too many
Is there a way to add word "number" which comes after word list but how many words after is unknown.
also, I can not understand from the help page how to make the regex case insensitive.

Thanks again.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Something like UNIX grep functionality (but not grep.ahk)

22 Apr 2018, 02:40

Add a positive lookahead for number, set the i) flag for case insensitive searching
User avatar
sooyke
Posts: 7
Joined: 21 Apr 2018, 10:23

Re: Something like UNIX grep functionality (but not grep.ahk)

22 Apr 2018, 02:54

You can do like swagfag suggest but if you are not familiar with regex , "lookahead" syntax needs some studying :)

easy way:

Code: Select all

data=
(
first line
my experiance as a medievaList.
some more lines list followed by number
ending lines
)

clipboard:=data

regexmatch(clipboard,"`ami)^.*List.*number.*$",out)
msgbox %   out

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Google [Bot], ShatterCoder and 112 guests