Re: Regular Expression Thickness Again

  • From: james.homme@xxxxxxxxxxxx
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Thu, 1 Nov 2007 11:06:47 -0400

Hi,
Is that \2 and \1 I put in there used for anything?

Thanks.

Jim

James D Homme, , Usability Engineering, Highmark Inc.,
james.homme@xxxxxxxxxxxx, 412-544-1810

"Never doubt that a thoughtful group of committed citizens can change the
world.  Indeed, it is the only thing that ever has." -- Margaret Mead



                                                                       
             "Veli-Pekka                                               
             Tätilä"                                               
             <vtatila@xxxxxxxx                                          To
             dent.oulu.fi>             programmingblind@xxxxxxxxxxxxx  
             Sent by:                                                   cc
             programmingblind-                                         
             bounce@freelists.                                     Subject
             org                       Re: Regular Expression Thickness
                                       Again                           
                                                                       
             11/01/2007 11:00                                          
             AM                                                        
                                                                       
                                                                       
             Please respond to                                         
             programmingblind@                                         
               freelists.org                                           
                                                                       
                                                                       




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



__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

Other related posts: