On Tue, Nov 18, 2008 at 9:52 AM, howa <[EMAIL PROTECTED]> wrote: > Hello, > > I have two strings: > > 1. abc > 2. abc& > > > The line of string might end with "&" or not, so I use the expression: > > (.*)[$&] > > > Why it didn't work out? > > > Thanks. > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > http://learn.perl.org/ > > >
This does not work because $ denotes the end of the string. So after $ there is no more string, matching something at the end of the string you would do by writting <something>$ so in your case: (.*)&$ (which will only match the line with & in there. If you want to capture both lines you end up doing somehting like this: (.*)&{0,1}$ Note: there are other ways to match both lines, just like perl it self regular expressions quite often ofer more then one way to do the same thing. Regards, Rob