On Sep 6, 2011, at 7:50 AM, jefferis wrote: > My client wants me to take a tool tip for hundreds of items and wants > me to add a tab after the item number and then remove numbers at the > end of the phrase. > > As a sample the numbers and letters up to the first space are the item > number. Description text is variable in lenght and the last set of > numbers are to be removed. The codes are only numbers preceded by a > space. > > 26119BCZZD002CR01 Edward Piguet Tourbillon with Diamond Bezel White > and lots of gold stuff 73245
BBEdit's help contains a good introduction to regular expressions and "GREP". I find most of the O'Reilly books little better than the help available online, but YMMV. I usually just google "regular expression converting telephone numbers" or whatever to find common patterns that I need, but of course you do need to know the basics to see if you're on the right track. You can think of the regexp is a little machine that consumes the string character by character. When one part of the pattern can't match any more it goes on to the next part. [A-Z0-9]+ will match a string of one or more capital letters or numbers. [0-9]+ will match a string of numbers. .* will match anything. So, your example will be matched by the following. You can test this by entering it into the find dialog and then command-g through some matches. [A-Z0-9]+ .* [0-9]+ To do a replace we identify the parts of the string we want to keep with parentheses. We want to keep the first and second parts and get rid of the third. The parentheses are otherwise basically ignored. They don't affect the match. ([A-Z0-9]+) (.*) [0-9]+ To create the replacement we reference the parentheses with \1 and \2 and add the tab. \1\t\2 Finally, if your data is in a file with one entry per line then you can add ^ and $ to the find pattern to ensure that you match only entire lines. Otherwise, if the data is embedded in other text you might need something a little different. Find: ^([A-Z0-9]+) (.*) [0-9]+$ Replace: \1\t\2 [fletcher] -- You received this message because you are subscribed to the "BBEdit Talk" discussion group on Google Groups. To post to this group, send email to bbedit@googlegroups.com To unsubscribe from this group, send email to bbedit+unsubscr...@googlegroups.com For more options, visit this group at <http://groups.google.com/group/bbedit?hl=en> If you have a feature request or would like to report a problem, please email "supp...@barebones.com" rather than posting to the group. Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>