Regular Expression line starts with 3 or 4

Hi,
 I am just learning regular expressions- can anyone help with this one? I am writing in C#.

I have a huge file and I want to extract out the data directory listed on lines that start with the number 3 or 4 and then a space.

sooooo....

3           CAROL B                                              1127872     20080208    ed/data/1127872/0001225208-08-002317.txt        
31           CAROL B                                              1127872     20080208    ed/data/1127872/0001225208-08-002318.txt        
4           CAROL B                                              1127872     20080208    ed/data/1127872/0001225208-08-002319.txt        

could return a matchcollection containing
data/1127872/0001225208-08-002317.txt
data/1127872/0001225208-08-002319.txt

Can anyone help??
toby_langAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
^[34]\s
0
mjcoyneCommented:
In Perl, I would do something like this:

#!/usr/bin/perl -w
use strict;
my $collection;

while (<DATA>) {
    next unless (/^[34]\s/);
    /ed\/(.+)/;
    $collection .= $1;
}

print $collection;

0
oleberCommented:
Using perl to get just the lines starting by 3 or 4 from a file

perl -ne 'print if /^[34]/' filename.txt

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

ddrudikCommented:
To arrive at your intended MatchCollection (apparently trimming the ed/ from the paths):
^[34]\s.*?ed/(.*) *

C#.NET Code Example:
using System;
using System.Text.RegularExpressions;
namespace myapp
{
  class Class1
    {
      static void Main(string[] args)
        {
          String sourcestring = "source string to match with pattern";
          Regex re = new Regex(@"^[34]\s.*?ed/(.*) *",RegexOptions.Multiline);
          MatchCollection mc = re.Matches(sourcestring);
          int mIdx = 0;
          foreach (Match m in mc)
           {
            for (int gIdx = 0; gIdx < m.Groups.Count; gIdx++)
              {
                Console.WriteLine("[" + mIdx + "][" + re.GetGroupNames()[gIdx] + "] = " + m.Groups[gIdx].Value);
              }
          }
        }
    }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
oleberCommented:
perl -ne 'print if /^[34]\s/' filename.txt
0
toby_langAuthor Commented:
Wow thanks very much for the help, that would have taken me forever to figure out- I had the first part the same as you but was really struggling with the second half. Thanks very much!
0
ddrudikCommented:
Thanks for the question and the points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.