TF library TF_RegExReplaceInLines

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
smbs
Posts: 98
Joined: 27 Feb 2014, 11:07

TF library TF_RegExReplaceInLines

02 Sep 2017, 04:56

Code: Select all

msgbox % TF_RegExReplaceInLines(TF(F),1,,   (".*name.*"),"")
Above works replaces all containing name with blank line
I want the opposite display only lines with "name' have tried many combo with no success ie

Code: Select all

msgbox % TF_RegExReplaceInLines(TF(F),1,,   (".*!name.*"),"")
Whats the correct syntax?
Thanx
Guest

Re: TF library TF_RegExReplaceInLines

02 Sep 2017, 06:34

Try

Code: Select all

MsgBox % TF_RegExReplaceInLines(TF(F),1,, "^((?!name).)*$","")
smbs
Posts: 98
Joined: 27 Feb 2014, 11:07

Re: TF library TF_RegExReplaceInLines

02 Sep 2017, 07:31

Code: Select all

[
    {
        "fname": "xxxxxxx",
        "dz": "yy1",
        "pp": "yyyyyyyyyy",
        "name": "my text",
        "bbb": "xxxxx",
        "sosss": "tttttttt",
        "mmmmr": "abc",
        "kkkkk": "yyyyyyy"
    },
I finally want to remain with 2 lines starting with name and fname
If it can be done in one go fine---- but as a beginner the first step is to have the 2 lines with name and fname staring in first column
I think your solution assumes no spaces at line beginning
This is from a .json file with many lines
Thanx
Guest

Re: TF library TF_RegExReplaceInLines

02 Sep 2017, 07:47

If I try it with the posted data the results here are
"fname": "xxxxxxx",


"name": "my text",
so that seems to be about right, it may very well be that that the json isn't formatted as you posted it. (sometimes JSON is just one very long line so no line breaks)
Depending on what you want to do and where you get the data you may be better off working with JSON directly (google json autohotkey and you'll find various scripts/libs)

You can also use TF_Find to just get the lines with "name" in them

Code: Select all

MsgBox % TF_Find(tf(f), , , "name", 0, 1) ; find all lines with "name" in them and return text
smbs
Posts: 98
Joined: 27 Feb 2014, 11:07

Re: TF library TF_RegExReplaceInLines

02 Sep 2017, 09:34

U are correct it works great! Had typo

Code: Select all

MsgBox % TF_RegExReplaceInLines(TF(F),1,, "^((?!name).)*$","")
can u explain the logic
below deletes all lines with "name"

Code: Select all

msgbox % TF_RegExReplaceInLines(TF(F),1,,   "^(.*(name).*)$","")
So why doesn't this below work?

Code: Select all

msgbox % TF_RegExReplaceInLines(TF(F),1,,   "^(.*(!name).*)$","")
Many thanx for your patience
Guest

Re: TF library TF_RegExReplaceInLines

02 Sep 2017, 17:03

! isn't used in regular expression as such, if you want a negative you need [^] - see https://autohotkey.com/docs/misc/RegEx-QuickRef.htm Classes of characters, but you don't want that here so you' re better off using a "Look-ahead" (bottom of that page), and in this case a negative as you don't want to have "name" in it.
smbs
Posts: 98
Joined: 27 Feb 2014, 11:07

Re: TF library TF_RegExReplaceInLines

02 Sep 2017, 17:34

Many thanx ---read the relevant docs and now understand the "look-ahead"
Again thanks for putting me in the right direction!
smbs
Posts: 98
Joined: 27 Feb 2014, 11:07

Re: TF library TF_RegExReplaceInLines

03 Sep 2017, 04:42

Guest!
Just as an exercise--I am trying to learn
Is it possible using one line only TF_RegExReplaceInLines(.........) to get output as shown below--only the relevant text of lines name and fname above
xxxxxxx
my text
I have tried all sorts of combinations without success
Thanx
smbs
Posts: 98
Joined: 27 Feb 2014, 11:07

Re: TF library TF_RegExReplaceInLines

03 Sep 2017, 04:42

double post deleted!
Last edited by smbs on 04 Sep 2017, 04:53, edited 1 time in total.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: DiegoSouto, Rohwedder, Sniperman and 384 guests