Brian Barker wrote: > At 19:51 21/08/2009 +0200, Jonathan Kaye wrote: >>Here is my second question, Pradeep, since you >>know regular expressions quite well. > > Sorry, I'm not Pradeep; will I do? Please don't be sorry, Brian. I feel I am being pampered by all this expert help; the more the merrier. :) > >>I want to match a string from the start of the >>record to the first full-stop (if any) in the >>record. That part is easy: ^.*\. gives me what I want. > > Actually, it's not quite as easy as > that. Regular expressions match as much as > possible: they are sometime described as > "greedy". So your expression matches everything > up to the *last* full stop in a paragraph, in fact. You need something > like > ^[^\.]*\. > instead. The part enclosed in square brackets > matches anything that is not a full stop. > Yes, I am aware of the "greedy" property. As you correctly saw I will be finding more than one match in a record and so doing more than one replacement. At some point I'll need something like this: [^| ][^\.]*\. so that the match start from either the beginning of a word or from a space (word break). >>Now the hard part: in the replace field, how can >>I refer to the material matched by .* ? > > By putting it in parentheses. You can refer to > strings that are matched by parenthesised expressions using $1, $2, and so > on. > >>I would like to surround the matched material >>with « at the beginning and » at the end. So, >>for example, if a have a record like this: >>delete.me, I would like to replace it with this: «delete»me Is this >>possible? > > Yes. Search for > ^([^\.]*)\. > and replace with > «$1» > > I trust this helps. > It help enormously. I'll give it a try and report back. > Brian Barker Thanks again, Brian. Cheers, Jonathan
-- Registerd Linux user #445917 at http://counter.li.org/ Please do not send me copies of list mail. I read the lists. Thanks! --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
