Re: [SLUG] Perl Regular expression help

2010-07-27 Thread Lindsay Holmwood
On 28/07/2010, at 1:03, Martin Barry wrote: You could get crazy and try to do this in a single regex but two stage is clearer. e.g. sed -e 's/&pg=[^&]*//g' -e 's/?pg=[^&]*&/?/' Now you have 2 problems. -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription in

Re: [SLUG] Perl Regular expression help

2010-07-27 Thread Jamie Wilkinson
Call me crazy! s/(&|?)pg=[^&]*/\1/ (correct escaping of & and ? left as an exercise for someone actually using this :) On 27 July 2010 08:03, Martin Barry wrote: > Sorry to bring up an old thread but I just had to comment on this... > > $quoted_author = "Jamie Wilkinson" ; > > > > Try: > > > >

Re: [SLUG] Perl Regular expression help

2010-07-27 Thread Martin Barry
Sorry to bring up an old thread but I just had to comment on this... $quoted_author = "Jamie Wilkinson" ; > > Try: > > /&pg=[^&]*/ > > match zero or more of the character class that is not an ampersand. Except there is nothing stopping the variables being reordered, no? So you may need to matc

Fwd: Re: [SLUG] Perl Regular expression help

2010-07-15 Thread Jon Jermey
Perhaps this is the time for me to ask: does anyone know a way for grep or awk to extract from a text file any sequence of up to, say, six words that begins and ends with an initially-capitalised word -- whether or not it is part of a larger matching sequence? So if the input text was: "Sall

Re: [SLUG] Perl Regular expression help

2010-07-14 Thread Peter Rundle
Thanks Nick, What I didn't know was that ^ inside brackets [] means "not". I was still reading ^ as "beginning of string". That will be very very useful in future. Thanks Pete Nick Andrew wrote: On Wed, Jul 14, 2010 at 01:27:13PM +1000, Peter Rundle wrote: I don't really understand how the

Re: [SLUG] Perl Regular expression help

2010-07-14 Thread Lindsay Holmwood
On 14/07/2010, at 13:27, Peter Rundle wrote: P.S I didn't understand Lindsay's question about doing the replace. I'm replacing the arg with nothing, I.E I just want to remove the "pg=" argument from the string. Didn't know what you were replacing your match with, was just curious abou

Re: [SLUG] Perl Regular expression help

2010-07-14 Thread Nick Andrew
On Wed, Jul 14, 2010 at 01:27:13PM +1000, Peter Rundle wrote: > I don't really understand how the [^&] followed by the * works but it does. "any character which is not an ampersand" repeated zero or more times. So it matches () ()& (a) (a)& (aaa...) (aaa...)& Where the stuff inside () is what's

Re: [SLUG] Perl Regular expression help

2010-07-13 Thread Peter Rundle
Thanks Jamie (and others), That works a treat. I would have tried /&pg=*[^&]/ which of course would have matched all &ersands up until the last taking out more than one argument. I don't really understand how the [^&] followed by the * works but it does. Thanks Pete P.S I didn't understand

Re: [SLUG] Perl Regular expression help

2010-07-13 Thread Jamie Wilkinson
I don't see the problem with my approach; the match will terminate when it sees the second ampersand, without consuming it. On 13 July 2010 19:01, Ken Foskey wrote: > > "/&pg=.*&/" > > >But also I think & is a special char (no?) that means "put the matched bit > back", though is that only

RE: [SLUG] Perl Regular expression help

2010-07-13 Thread Ken Foskey
> "/&pg=.*&/" >But also I think & is a special char (no?) that means "put the matched bit back", though is that only on the replace side? (my question relates strictly to the matching side). Yes the ampersand is special, it represents the complete matched string on the replace. s/&pg=.*

Re: [SLUG] Perl Regular expression help

2010-07-13 Thread Tony Sceats
how about using a slightly different approach with split @input = split /\&/; $input[0] should now be pg=something, $input[1] will be the args=somthingelse so you can trivially match, modify and print this to your output, whether or not it has extra arguments. On Wed, Jul 14, 2010 at 11:24

Re: [SLUG] Perl Regular expression help

2010-07-13 Thread Jamie Wilkinson
I'd use a global search and replace command, if it were me, and I was using sed: sed -ie 's/&pg=[^&]//g' lindsay.html On 13 July 2010 18:13, Lindsay Holmwood wrote: > Now you've got the search, I'm curious how you are going to do the replace. > > Is the Perlism to just use the substitute operato

Re: [SLUG] Perl Regular expression help

2010-07-13 Thread Lindsay Holmwood
Now you've got the search, I'm curious how you are going to do the replace. Is the Perlism to just use the substitute operator, or split on the pattern, iterate through the array, and join again? Lindsay On 14 July 2010 10:30, Jamie Wilkinson wrote: > Try: > > /&pg=[^&]*/ > > match zero or more

Re: [SLUG] Perl Regular expression help

2010-07-13 Thread Jamie Wilkinson
Try: /&pg=[^&]*/ match zero or more of the character class that is not an ampersand. On 13 July 2010 17:21, Peter Rundle wrote: > Hi Sluggers, > > I'm sure some of you genii have a real quick solution to this. > > I'm trying to find and replace and argument in a url. The url is of the > form >

[SLUG] Perl Regular expression help

2010-07-13 Thread Peter Rundle
Hi Sluggers, I'm sure some of you genii have a real quick solution to this. I'm trying to find and replace and argument in a url. The url is of the form &pg=something&arg=somethingelse I want to take out the &pg=something but the "&arg=" may or may not be there. How do I say match the &pg=som