Page 1 of 1

Regex in multi lines text?

Posted: 30 Mar 2020, 20:43
by joshatt
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.

Re: Regex in multi lines text?  Topic is solved

Posted: 30 Mar 2020, 20:54
by boiler
Try \v instead of \n to match any vertical whitespace character.

Re: Regex in multi lines text?

Posted: 30 Mar 2020, 22:17
by joshatt
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.

Re: Regex in multi lines text?

Posted: 30 Mar 2020, 22:18
by teadrinker

Code: Select all

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

Re: Regex in multi lines text?

Posted: 30 Mar 2020, 22:25
by joshatt
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.