Wikipedia:Reference desk/Archives/Computing/2017 September 26

From Wikipedia, the free encyclopedia
Computing desk
< September 25 << Aug | September | Oct >> September 27 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


September 26[edit]

Regex: How to delete all comments and all that comes after them in a row?[edit]

I tried this:

 ?^# *

To delete all commets starting with #space (and that might be preceded by a space).

It does delete them, but not everything coming after them in the same row. Ben-Yeudith (talk) 06:34, 26 September 2017 (UTC)[reply]

Try "^ ?# .*" based on your description, if a comment is always on its own line. The last two characters (.*) means 'everything'. -- zzuuzz (talk) 07:11, 26 September 2017 (UTC)[reply]
Hmm, sadly this seems to delete everything in the file, not only comments. Ben-Yeudith (talk) 07:19, 26 September 2017 (UTC)[reply]
Depending on how you open the file, ".*" will usually match newline characters as well. ^ ?# [^\n]* could work (I have not tested it) ([^\n] means "any non-newline character"). TigraanClick here to contact me 11:05, 26 September 2017 (UTC)[reply]
I'm far too used to multiline. There may be an option for 'multiline mode' in your editor or particular language, possibly /m or (?m), which would make the expression "(?m)^ ?# .*" -- zzuuzz (talk) 11:43, 26 September 2017 (UTC)[reply]
If you want to express " lines that begins with # or with space and #" that won't be
?^
This
^
matches the beginning, there's nothing before the beginning, optional or not. Make the space optional.B8-tome (talk) 12:20, 26 September 2017 (UTC)[reply]
The following worked. Thanks.
# [^\n]*

Ben-Yeudith (talk) 13:27, 26 September 2017 (UTC)[reply]

That works as long as '#' does not appear on non-comment lines. If you get any code line with '#' in it, it will be deleted too. Just apply a regexp that exactly defines what a valid comment is.B8-tome (talk) 13:57, 26 September 2017 (UTC)[reply]