views:

61

answers:

3

I must admit it's been a few years since my RegEx class and since then, I have done little with them. So I turn to the brain power of SO. . .

I have an Excel spreadsheet (2007) with some data. I want to search one of the columns for a pattern (here's the RegEx part). When I find a match I want to copy a portion of the found match to another column in the same row.

A sample of the source data is included below. Each line represents a cell in the source.

I'm looking for a regex that matches "abms feature = XXX" where XXX is a varibale length word - no spaces in it and I think all alpha characters. Once I find a match, I want to toss out the "abms feature = " portion of the match and place the code (the XXX part) into another column.

I can handle the excel coding part. I just need help with the regex.

If you can provide a solution to do this entirely within Excel - no coding required, just using native excel formula and commands - I would like to hear that, too.

Thanks!

###################################  
Structure
abms feature = rl

abms feature = sta

abms feature = pc, pcc, pi, poc, pot, psc, pst, pt, radp
font = 5               abms feature = equl, equr


abms feature = bl

abms feature = tl

abms feature = prl





font = 5
###################################
A: 

Try this regular expression:

abms feature = (\w+)

Here is an example of how to extract the value from the capture group:

using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main()
    {
     Regex regex = new Regex(@"abms feature = (\w+)",
      RegexOptions.Compiled |
      RegexOptions.CultureInvariant |
      RegexOptions.IgnoreCase);

     Match match = regex.Match("abms feature = XXX");

     if (match.Success)
     {
      Console.WriteLine(match.Groups[1].Value);
     }
    }
}
Andrew Hare
A: 

(?<=^abms feature = )[a-zA-Z]*

assuming you're not doing anything with the words after the commas

Victor
Sorry, I intended to mention that in my post. No, I am not using anything after the comma.
Scott
+1  A: 

I am still learning about regex myself, but I have found this place useful for getting ideas or comparing what I came up with, might help in the future? http://regexlib.com/

thatryan