Regex in multi lines text? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
joshatt
Posts: 105
Joined: 07 Dec 2014, 08:41
Facebook: joshatt
Google: joshatt

Regex in multi lines text?

30 Mar 2020, 20:43

Hi all,

Code: Select all

alltext=
(
adfdsff
efresfsdf
AAA:randomwords
EFDFDF
)
out:=RegExReplace(alltext,"m).*\nAAA:(.*)\n.*","$1")
MsgBox,% out
For testing purpose, I keyboarded the above multi lines paragraph, and the two "\n" works(but "\r" won't). My goal is to get "randomwords", without any other words.
But then when I try to use this into reality, grabbing some multi-line paragraph else where, it does not work.
I tried different things: \n, \r, sm), $.......most cases it removes nothing leaving me whole paragraph, other cases it leaves me "randomwords" and next line. I can not tell if my regex usage is wrong or it's because I don't know how to identify what kind of line return is used in real life.

Then I tried regex lazy:

Code: Select all

out:=RegExReplace(alltext,"m).*AAA:(.*?)$.*","$1")
which still leaves me "randomwords" and next line.

Any idea? Please help.
User avatar
boiler
Posts: 5295
Joined: 21 Dec 2014, 02:44

Re: Regex in multi lines text?  Topic is solved

30 Mar 2020, 20:54

Try \v instead of \n to match any vertical whitespace character.
joshatt
Posts: 105
Joined: 07 Dec 2014, 08:41
Facebook: joshatt
Google: joshatt

Re: Regex in multi lines text?

30 Mar 2020, 22:17

boiler wrote:
30 Mar 2020, 20:54
Try \v instead of \n to match any vertical whitespace character.
WOW, vertical whitespace? new one for me.
It works great!
My real-world example is more complicated, I don't know why it HAS TO be like this, but the following changing works:

Code: Select all

out:= RegExReplace(alltext,"s).*Avid:(.*?)\v.*","$1")
s) instead of m)
?
\v
these three are necessary.
Last edited by joshatt on 30 Mar 2020, 22:21, edited 1 time in total.
teadrinker
Posts: 1643
Joined: 29 Mar 2015, 09:41
Contact:

Re: Regex in multi lines text?

30 Mar 2020, 22:18

Code: Select all

alltext := "adfdsff`r`n"
         . "efresfsdf`r`n"
         . "AAA:randomwords`r`n"
         . "EFDFDF"
out:=RegExReplace(alltext,"s).*\RAAA:(.*?)\R.*","$1")
MsgBox,% "|" . out . "|"
joshatt
Posts: 105
Joined: 07 Dec 2014, 08:41
Facebook: joshatt
Google: joshatt

Re: Regex in multi lines text?

30 Mar 2020, 22:25

teadrinker wrote:
30 Mar 2020, 22:18

Code: Select all

alltext := "adfdsff`r`n"
         . "efresfsdf`r`n"
         . "AAA:randomwords`r`n"
         . "EFDFDF"
out:=RegExReplace(alltext,"s).*\RAAA:(.*?)\R.*","$1")
MsgBox,% "|" . out . "|"
Thanks! That works great.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Rohwedder and 41 guests