Re: Substitution/Regex problem

2004-05-02 Thread Cedric Godin
On Thursday 29 April 2004 10:31, Owen wrote: > I would like to replace all instances of > > @non_space_characters[non_space_characters] with > $non_space_characters[non_space_characters] > > The program below gets the first one only. How do I get the others? > > TIA > > Owen > ---

Re: Substitution/Regex problem

2004-04-29 Thread John W. Krahn
Owen wrote: > > I would like to replace all instances of > > @non_space_characters[non_space_characters] with > $non_space_characters[non_space_characters] > > The program below gets the first one only. How do I get the others? > > --- > #!/usr/

Re: Substitution/Regex problem

2004-04-29 Thread Damon Allen Davison
Hi Owen, I think I would do things a little differently. Owen wrote: I would like to replace all instances of @non_space_characters[non_space_characters] with $non_space_characters[non_space_characters] [...] $line=~s/(@)(\S+\[\S+\])/\$$2/g; __DATA__ @[EMAIL PROTECTED]@banana[4]; So this is my

Re: Substitution/Regex problem

2004-04-29 Thread Jose Alves de Castro
The problem is that your regex is matching the whole line: @ [EMAIL PROTECTED]@banana[4]; ^ ^ $1 $2 Instead, use non greedy matches: $line =~ s/(@)(\S+?\[\S+?\])/\$$2/g; and you'll get what you want: @ array[1] = @ array[2] +@ banana[4]; ^ ^