256 Kilobytes

Answers in Scripting and Automation | By Some Guy

Published 4 days agoFri, 11 Jan 2019 19:28:38 -0800

7 views, 0 RAM, and 1 comment

Profile Photo - Some Guy Some Guy
🗎 2220 🗨 4 🐏 4
Classic User

I have been trying to use REGEX to wrap a line of text in double quotes. Is anyone familiar with this procedure that can walk me through the process?

Download more RAM. 🐏 ⨉ 0 Posted by Some Guy 4 days ago 🕓 Posted at 11 January, 2019 19:28 PM PST

This is a patsy account used by the 256 Kilobytes staff to seed content. 

Profile Photo - August R. Garcia August R. Garcia Posting on Internet... Portland, OR
🗎 33 🗨 319 🐏 25
Site Owner

You should be able to do this with:

  • Either:
    • s/^\|$/"/g
  • Or:
    • /^|$/gm

Syntax broken down by Regex101's automated tool for the REGEX /^|$/gm:

  • 1st Alternative ^
    • ^ asserts position at start of a line
  • 2nd Alternative $
    • $ asserts position at the end of a line
  • Global pattern flags
    • g modifier: global. All matches (don't return after first match)
    • m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)

Note that whether to escape the pipe character or not depends on the REGEX implementation/whatever. More information:

Pipe character should be escaped with a single backslash in a Perl regex. (Perl regexes are a bit different from POSIX regexes. If you're using this in, say, grep, things would be a bit different.) If you're specifically looking for a space between them, then use an unescaped space. They're perfectly acceptable in a Perl regex. Here's a brief test program:

Source: https://stackoverflow.com/questions/182635/how-can-i-match-a-pipe-character-followed-by-whitespace-and-another-pipe

Download more RAM. 🐏 ⨉ 0 Posted by August R. Garcia 4 days ago 🕓 Posted at 11 January, 2019 19:32 PM PST

The CIA wants all code in the cloud under their lock and key.  They want to ban compilers and make people think HTML is computer programming. - Terry A. Davis

Post a New Comment

To leave a comment, login to your account or create an account.