Re: Regular Expression Thickness Again

  • From: Veli-Pekka Tätilä <vtatila@xxxxxxxxxxxxxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Thu, 01 Nov 2007 17:00:22 +0200

Hi James,
Try something like the following, untested:

Find: ^(function|script)(.*)

Replace with: $2$1 

Here we say at the beginning of a line 
either function or script captured 
followed by 0 or more but as many as you can of non new-lines captured.
Then we instruct the regexp engine to replace the whole match with the
secondly matched bit followed by the firstly matched bit.

This is assuming a Perl 5 compliant regexp engine or PCRE. I don't know
what the editor uses you mentioned. But the principles are much the
same:

Note most engines use parens for capturing groups, brackets are for
character classes and braces for repetition counts i.e. quantifiers.
Some use the back slash before one, others use the dollar. Perl actually
stores any recently matched capturing groups into variables named $1, $2
etc... Also you don't need the dollar inside the second capturing group.
It anchors a match but per se matches 0 characters, so it need not be
included, if I've understood things correctly.

Any corrections welcome. THis is just a quick reply I haven't even
consulted a proper reference for this.

--  
With kind regards Veli-Pekka Tätilä (vtatila@xxxxxxxxxxxxxxxxxxxx)
Accessibility, game music, synthesizers and programming:
http://www.student.oulu.fi/~vtatila

james.homme@xxxxxxxxxxxx wrote:
> Hi,
> I put builtin.jsd into EdSharp. I want to swap the first word on every line
> with the rest of the line if that line begins with either the word function
> or the word script.
> 
> My search expression is this.
> (^[function|script])(.*$)
> 
> My replacement expression is this.
> \2\1
> 
> When I execute the replacement operation, the whole line disappears. What
> did I do wrong?
> 
> Thanks.
__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: