Regex to remove comment lines Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
john_c
Posts: 493
Joined: 05 May 2017, 13:19

Regex to remove comment lines

01 Jul 2019, 10:38

Code: Select all

Test =
(
;       Foo
;Bar
;  aaa   aaaaa
Baz
)

Test := RegExReplace(Test, "???", "")
MsgBox % Test
Please, help me with regex. I need to remove any comment lines. I.e. only the Baz line should be kept.
User avatar
Datapoint
Posts: 295
Joined: 18 Mar 2018, 17:06

Re: Regex to remove comment lines  Topic is solved

01 Jul 2019, 10:48

"`am)^\s*;.*(?:\R|$)"
Last edited by Datapoint on 01 Jul 2019, 10:53, edited 1 time in total.
john_c
Posts: 493
Joined: 05 May 2017, 13:19

Re: Regex to remove comment lines

01 Jul 2019, 10:53

@Datapoint Thanks for your input, but the MsgBox is blank...

upd: Ah, after your edit it works. Thanks again.
User avatar
Datapoint
Posts: 295
Joined: 18 Mar 2018, 17:06

Re: Regex to remove comment lines

01 Jul 2019, 10:54

edited my previous post to add the `a
https://regex101.com/r/618UAe/1
teadrinker
Posts: 4326
Joined: 29 Mar 2015, 09:41
Contact:

Re: Regex to remove comment lines

01 Jul 2019, 11:33

If the comment line is the last one, the line break won't be removed by this way:

Code: Select all

Test =
(
;       Foo
;Bar
;  aaa   aaaaa
Baz
;  last comment
)

Test := RegExReplace(Test, "`am)^\s*;.*(?:\R|$)")
MsgBox % "|" Test "|"
Better like this:

Code: Select all

Test =
(
;       Foo
;Bar
;  aaa   aaaaa
Baz
;  last comment
)

Test := RegExReplace(Test, "m`a)(\R)?^\s*;.*(?(1)|\R)")
MsgBox % "|" Test "|"
john_c
Posts: 493
Joined: 05 May 2017, 13:19

Re: Regex to remove comment lines

01 Jul 2019, 11:54

@teadrinker Thanks! (Ah, I was sure I know something about regular expressions!)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder, wjt936826577 and 304 guests