Split - to many lines Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Albireo
Posts: 1756
Joined: 16 Oct 2013, 13:53

Split - to many lines

17 Nov 2020, 10:22

Hi!
this work

Code: Select all

A .= info1 ";" info2 ";" Trim(Info3) "`n"
but this does not work for me .:

Code: Select all

A .=
( 	info1 ";"
	info2 ";"
	Trim(info3) "`n"
)
or this .:

Code: Select all

A .= .
( 	info1 ";" .
	info2 ";" .
	Trim(info3) "`n"
how to solve this?
User avatar
mikeyww
Posts: 27068
Joined: 09 Sep 2014, 18:38

Re: Split - to many lines  Topic is solved

17 Nov 2020, 10:25

Code: Select all

A .= info1 ";"
  .  info2 ";"
  .  Trim(info3) "`n"
Albireo
Posts: 1756
Joined: 16 Oct 2013, 13:53

Re: Split - to many lines

19 Nov 2020, 05:27

Is it possible to split

Code: Select all

invRow ~= "(.*\s+((\d+.)?\d+,\d+)\s+.*\s+((\d+,\d+)\s[%])\s+((\d+.)?\d+,\d+)\s+((\d+.)?\d+,\d+))$" )
to many lines with comments?
Something like this .:

Code: Select all

invRows ~=
( LTrim Join Comments
   (.*\s+   ; bla bla 
   ((\d+.)?\d+,\d+)   ; New Comments
      ...
   etc.
)
(I did not make it work)
User avatar
mikeyww
Posts: 27068
Joined: 09 Sep 2014, 18:38

Re: Split - to many lines

19 Nov 2020, 06:51

Interesting issue. My best guess is that + is somehow being interpreted as a literal character, rather than a regex character. The following works.

Code: Select all

regex =
( LTrim Join Comments
   (.*\s+     ; Line 1
   ((\d+.)?   ; Line 2
   \d+,\d+))  ; Line 3
)
invRows = x 3l6,0 ; Example to see whether the regex works

; Show results
info = regex       %regex%`n`ninvRows   %invRows%`n`n
If invRows ~= regex
 MsgBox, 64, Success, %info%It worked!
Else MsgBox, 48, Failure, %info%Nope!
just me
Posts: 9482
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Split - to many lines

19 Nov 2020, 07:03

The regex needle is a simple string so the concat operator . should work as already shown by mikeyww .
User avatar
mikeyww
Posts: 27068
Joined: 09 Sep 2014, 18:38

Re: Split - to many lines

19 Nov 2020, 07:11

Yes, that works, too. It also appears that \s is tripping up the problematic code, so perhaps the continuation section also does not like the backslash somehow when used with ~=. Below, the first script fails; the second and third succeed.

Code: Select all

If "5" ~=
(
\d
)
MsgBox, Success

Code: Select all

regex =
(
\d
)
If "5" ~= regex
MsgBox, Success

Code: Select all

If "5" ~=
(
5
)
MsgBox, Success
User avatar
boiler
Posts: 17050
Joined: 21 Dec 2014, 02:44

Re: Split - to many lines

19 Nov 2020, 07:59

It’s because ~= an expression operator, so literal strings, like in the first example, must be quoted. It’s similar to using a continuation section like that with := instead of =. The following works:

Code: Select all

If "5" ~= "
(
\d
)"
MsgBox, Success

The second example uses the legacy assignment operator =, so the assignment works unquoted. The third example works because it’s being assigned a value, not a string, so no quotes are needed.
User avatar
mikeyww
Posts: 27068
Joined: 09 Sep 2014, 18:38

Re: Split - to many lines

19 Nov 2020, 08:05

Interesting again! Thanks, @boiler. You solved the mystery.
Albireo
Posts: 1756
Joined: 16 Oct 2013, 13:53

Re: Split - to many lines

19 Nov 2020, 09:45

Thanks!
But the only way to be able to write notes, is to follow mikeyww's first suggestion?

Code: Select all

regex =
( LTrim Join Comments
   (.*\s+     ; Line 1
   ((\d+.)?   ; Line 2
   \d+,\d+))  ; Line 3
)
invRows = x 3l6,0 ; Example to see whether the regex works

; Show results
info = regex       %regex%`n`ninvRows   %invRows%`n`n
If invRows ~= regex
 MsgBox, 64, Success, %info%It worked!
Else MsgBox, 48, Failure, %info%Nope!
just me
Posts: 9482
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Split - to many lines

19 Nov 2020, 09:53

It might help to try the other suggestions.
Albireo
Posts: 1756
Joined: 16 Oct 2013, 13:53

Re: Split - to many lines

19 Nov 2020, 17:32

To split @boiler has a nice suggestion.
(but I miss being able to make notes)
User avatar
boiler
Posts: 17050
Joined: 21 Dec 2014, 02:44

Re: Split - to many lines

19 Nov 2020, 17:43

You can make your notes. Did you try it?

Code: Select all

invRows = x 3l6,0 ; Example to see whether the regex works
if invRows ~= "
( LTrim Join Comments
   (.*\s+     ; Line 1
   ((\d+.)?   ; Line 2
   \d+,\d+))  ; Line 3
)"
	MsgBox, 64, Success, It worked!
Else
	MsgBox, 48, Failure, Nope!
just me
Posts: 9482
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Split - to many lines

20 Nov 2020, 05:44

just me wrote:
19 Nov 2020, 07:03
The regex needle is a simple string so the concat operator . should work as already shown by mikeyww .

Code: Select all

invRows := "x 3l6,0" ; Example to see whether the regex works
if invRows ~= "(.*\s+"     ; Line 1
            . "((\d+.)?"   ; Line 2
            . "\d+,\d+))"  ; Line 3
	MsgBox, 64, Success, It worked!
Else
	MsgBox, 48, Failure, Nope!
:!:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], jollyjoe, mikeyww and 278 guests