Hi,
I have read list.txt as a variable called mylist
list.txt contained these lines
yes-4k
4k
a4k
sk-4k
no.4k
4k-3
Then I had an input box asking me to check to see if a line exists - var
I'm trying to use regexmatch to do this.
pos := RegExMatch(mylist, var , SubPat)
Then I need to check if it exists without looping through each line
If (var = subpat1)
msgbox, yes
Else
msgbox, no
Some No results would be when var = 4k- or s-4k or sk-4
I have experimented with borders and whitespace, /n , $ and ^ etc but no joy.
regexmatch match any line exactly in list problem Topic is solved
Re: regexmatch match any line exactly in list problem
its not clear what you want
post a snippet of or your full code and explain whats wrong with it
post a snippet of or your full code and explain whats wrong with it
Re: regexmatch match any line exactly in list problem
Hi,
I want to be able to type in one of those lines that are in list.txt to an input box then adjust list.txt so that it removes the exact line I entered.
FileRead, mylist, list.txt
inputbox, var, word to match, input word
myfind := "\b(" . var. "\b)"
pos := RegExMatch(mylist, myfind , subpat)
If (match = subpat)
msgbox, found input
mylist := regexreplace(mylist, myfind,"`n")
msgbox, %mylist%
If I type in 4k, I just want it to remove the line with 4k in it. It's removing the one's next to boundaries which I have learned includes non word characters.
I want to be able to type in one of those lines that are in list.txt to an input box then adjust list.txt so that it removes the exact line I entered.
FileRead, mylist, list.txt
inputbox, var, word to match, input word
myfind := "\b(" . var. "\b)"
pos := RegExMatch(mylist, myfind , subpat)
If (match = subpat)
msgbox, found input
mylist := regexreplace(mylist, myfind,"`n")
msgbox, %mylist%
If I type in 4k, I just want it to remove the line with 4k in it. It's removing the one's next to boundaries which I have learned includes non word characters.
Re: regexmatch match any line exactly in list problem
Code: Select all
list=
(
yes-4k
4k
a4k
sk-4k
no.4k
4k-3
)
lineToRemove := "4k" ; change to remove the line you desire
list := RegExReplace(list, "m`a)^" lineToRemove "$\r*\n*")
MsgBox % list
ExitApp
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Re: regexmatch match any line exactly in list problem
Thanks Odlanir. This didn't work for me if I typed in ...4k
My list can contain entries with a-zA-Z0-9_\-\. in all kinds of crazy orders
...4k removed sk-4k and no.4k
I can acheive what I need with a loop but with 1000's of entries, i'm looking for efficiency.
My list can contain entries with a-zA-Z0-9_\-\. in all kinds of crazy orders
...4k removed sk-4k and no.4k
I can acheive what I need with a loop but with 1000's of entries, i'm looking for efficiency.
Re: regexmatch match any line exactly in list problem
What do you mean? The code Odlanir posted, works perfectly.pcb wrote:Thanks Odlanir. This didn't work for me if I typed in ...4k
My list can contain entries with a-zA-Z0-9_\-\. in all kinds of crazy orders
...4k removed sk-4k and no.4k
I can acheive what I need with a loop but with 1000's of entries, i'm looking for efficiency.
Just replace lineToRemove with an InputBox:
Code: Select all
list=
(
yes-4k
4k
a4k
sk-4k
no.4k
4k-3
)
InputBox, Input , String! -> Delete line, Type the contents of the line that you want to delete:,, 200, 150
list := RegExReplace(list, "m`a)^" Input "$\r*\n*")
MsgBox % list
Re: regexmatch match any line exactly in list problem
Not for me.Cuadrix wrote: What do you mean? The code Odlanir posted, works perfectly.
What happens if you add anther string to the list, eg ...4k
Then you enter ...4k as the input to remove the line. 3 entries disappear.
Re: regexmatch match any line exactly in list problem Topic is solved
It works if you prefix all the regex special chars in haystack with backslash.
Code: Select all
list := RegExReplace(list, "m`a)^" RegExReplace(input, "[-[\]{}()*+?.,\\/^$|#]", "\$0") "$\R*")
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Re: regexmatch match any line exactly in list problem
Thank you Odlanir. Regexpert level 1 million!
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 190 guests