Author Topic: change - insert newline?  (Read 5448 times)

glimt

  • Community Member
  • Posts: 15
  • Hero Points: 0
change - insert newline?
« on: January 01, 2009, 11:53:23 pm »
If I'm doing a search/replace via the change command how can I insert a newline?  E.g.

c/something/something\n inserts a literal "something\n"
c/something/something$ inserts a literal "something$"

Thanks

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: change - insert newline?
« Reply #1 on: January 02, 2009, 12:26:06 am »
You need to add the option for using regular expressions e.g.
c/something/something\n/u
specifying UNIX regex (or '/r' for SE syntax).
Also try 'help c' on commandline for further details ;)
Good luck, HS2

glimt

  • Community Member
  • Posts: 15
  • Hero Points: 0
Re: change - insert newline?
« Reply #2 on: January 02, 2009, 02:02:08 am »
Thanks for the reply.

There aren't any examples that involved inserting a newline in the helpfile.


jimlangrunner

  • Senior Community Member
  • Posts: 354
  • Hero Points: 30
  • Jim Lang - always a student.
Re: change - insert newline?
« Reply #3 on: January 02, 2009, 03:41:35 am »
Hi.  I'm kinda fond of the SE regEx, so that's how this example is constructed.  Consider:
Code: [Select]
$rstE = mysql_query($query_rstE, $jimlang_events) or die(mysql_error());
$row_rstE = mysql_fetch_assoc($rstE);
$totalRows_rstE = mysql_num_rows($rstE);

Now, let's say I want a comment and blank line to follow every line ending in "($rstE);"
My expression is:
Code: [Select]
{\(\$rstE\);}\nand I'll replace it with
Code: [Select]
#0\n//comment line here...\n\nwhich then gives me:
Code: [Select]
$rstE = mysql_query($query_rstE, $jimlang_events) or die(mysql_error());
$row_rstE = mysql_fetch_assoc($rstE);
//comment line here...

$totalRows_rstE = mysql_num_rows($rstE);
//comment line here...

Specifically, in the find & replace dialog, the Reg Ex has to be selected AND you have to have the right kind.

Does that help?

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: change - insert newline?
« Reply #4 on: January 02, 2009, 10:29:22 am »
@glimt: I only wanted to refer to the help contents concerning the replace ('c' command) options and regular expressions since '\n' is a regex token.
HS2