Doubt - Extract Text (RegExMatch) Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
snowmind
Posts: 124
Joined: 12 Nov 2015, 15:18

Doubt - Extract Text (RegExMatch)

07 Nov 2019, 15:44

hi folks :wave:

How can I extract the word WINDOWS from this text?

{"id":"restaura_senha","activitygroup":"8","campos":[{"value":"WINDOWS","label":"Sistema"},{"value":"684067 - jonh Smith tonelli","label":"Usuário que acessa o sistema"},{"value":"solicito reset de senha urgente\r\n\r\n684067 - jonh smithtonelli","label":"Justificativa"}],"nome":"Restaura Senha"}


I tried something with regxmatch but was unsuccessful.
* The text above was in my clipboard

Code: Select all

RegExMatch(clipboard, "value\s?:(.*) \,", match)
Var = %match1%
Msgbox % Var
awel20
Posts: 211
Joined: 19 Mar 2018, 14:09

Re: Doubt - Extract Text (RegExMatch)  Topic is solved

07 Nov 2019, 17:23

Hi snowmind,

Is this what you want? It will only get the first match (WINDOWS).

Code: Select all

Var = {"id":"restaura_senha","activitygroup":"8","campos":[{"value":"WINDOWS","label":"Sistema"},{"value":"684067 - jonh Smith tonelli","label":"Usuário que acessa o sistema"},{"value":"solicito reset de senha urgente\r\n\r\n684067 - jonh smithtonelli","label":"Justificativa"}],"nome":"Restaura Senha"}
RegExMatch(Var, "value\s?"":""\K([^""]+)", Match)
MsgBox % Match
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Doubt - Extract Text (RegExMatch)

07 Nov 2019, 18:59

You may want to make sure it always finds the value which corresponds to the label "Sistema" instead of relying on it being the first label. If so, this will find it:

Code: Select all

Haystack = {"id":"restaura_senha","activitygroup":"8","campos":[{"value":"WINDOWS","label":"Sistema"},{"value":"684067 - jonh Smith tonelli","label":"Usuário que acessa o sistema"},{"value":"solicito reset de senha urgente\r\n\r\n684067 - jonh smithtonelli","label":"Justificativa"}],"nome":"Restaura Senha"}
Needle = (?<=value":")[^"]*(?=","label":"Sistema")
RegExMatch(Haystack, Needle, Sistema)
MsgBox, % Sistema
snowmind
Posts: 124
Joined: 12 Nov 2015, 15:18

Re: Doubt - Extract Text (RegExMatch)

08 Nov 2019, 07:15

awel20 wrote:
07 Nov 2019, 17:23
Hi snowmind,

Is this what you want? It will only get the first match (WINDOWS).

Code: Select all

Var = {"id":"restaura_senha","activitygroup":"8","campos":[{"value":"WINDOWS","label":"Sistema"},{"value":"684067 - jonh Smith tonelli","label":"Usuário que acessa o sistema"},{"value":"solicito reset de senha urgente\r\n\r\n684067 - jonh smithtonelli","label":"Justificativa"}],"nome":"Restaura Senha"}
RegExMatch(Var, "value\s?"":""\K([^""]+)", Match)
MsgBox % Match
Hello awel20, thanks for replying

So the word is not always "WINDOWS". In this same place can come another word sometimes, like:

{"id":"restaura_senha","activitygroup":"8","campos":[{"value":"EMULATOR","label":"Sistema"},{"value":"684067 - jonh Smith tonelli","label":"Usuário que acessa o sistema"},{"value":"solicito reset de senha urgente\r\n\r\n684067 - jonh smithtonelli","label":"Justificativa"}],"nome":"Restaura Senha"}

In this case I should take the word "EMULATOR"
snowmind
Posts: 124
Joined: 12 Nov 2015, 15:18

Re: Doubt - Extract Text (RegExMatch)

08 Nov 2019, 07:17

awel20 wrote:
07 Nov 2019, 17:23
Hi snowmind,

Is this what you want? It will only get the first match (WINDOWS).

Code: Select all

Var = {"id":"restaura_senha","activitygroup":"8","campos":[{"value":"WINDOWS","label":"Sistema"},{"value":"684067 - jonh Smith tonelli","label":"Usuário que acessa o sistema"},{"value":"solicito reset de senha urgente\r\n\r\n684067 - jonh smithtonelli","label":"Justificativa"}],"nome":"Restaura Senha"}
RegExMatch(Var, "value\s?"":""\K([^""]+)", Match)
MsgBox % Match
But your answer is perfect. Thank you for your help :bravo:
snowmind
Posts: 124
Joined: 12 Nov 2015, 15:18

Re: Doubt - Extract Text (RegExMatch)

08 Nov 2019, 07:18

boiler wrote:
07 Nov 2019, 18:59
You may want to make sure it always finds the value which corresponds to the label "Sistema" instead of relying on it being the first label. If so, this will find it:

Code: Select all

Haystack = {"id":"restaura_senha","activitygroup":"8","campos":[{"value":"WINDOWS","label":"Sistema"},{"value":"684067 - jonh Smith tonelli","label":"Usuário que acessa o sistema"},{"value":"solicito reset de senha urgente\r\n\r\n684067 - jonh smithtonelli","label":"Justificativa"}],"nome":"Restaura Senha"}
Needle = (?<=value":")[^"]*(?=","label":"Sistema")
RegExMatch(Haystack, Needle, Sistema)
MsgBox, % Sistema
Hi boiler! your answer is perfect too. Thank you for your help

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 247 guests