Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7495105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:59:01+00:00 2026-05-29T17:59:01+00:00

I am working on a project to parse out a text file. The file

  • 0

I am working on a project to parse out a text file. The file is output from networking equipment. The incoming string is anywhere from a few thousand to tens of thousands of lines long. There will be a variable number of entries with keywords like these:

fcN/N is up
   Hardware is Fibre Channel, SFP is short wave laser w/o OFC (SN)
   Port WWN is 20:52:00:0d:ec:ef:b0:40
    Admin port mode is F, trunk mode is on
    snmp link state traps are enabled
    Port vsan is 10

fcipN is up
.....

port-channel-N is trunking
...... 

The N is a number. There will always be the ‘fcN/N’ entries, there may or may not be the other two. The ‘fcip’ and ‘port-channel’ entries will have similar status information after each one as the fcN/N entries. All entries of the same type will be grouped – there won’t be an fc followed by an fcip followed by another fc. Also as a general rule, all the fc entries are listed, then all the port-channel then all the fcip but I don’t want to assume that. At the moment I have about 7 different RegEx patterns I am looking for. I do this by examining each line in turn, however managing all those is cumbersome. I thought about splitting the string on newline and then some kind of LINQ select to get all of each of the 3 types of entries, but that assumes they are always grouped in the same order. I also thought about 3 monster regexes to match everything from one entry to the next, but my experience is those are tough to get working and almost unreadable. Another thing I thought of was first match the three keywords – fc or port-channel or fcip, then have an if statement that matches the patterns unique to those. That is still matching each line for all 3 patterns though.

To be clear, I have the Regex patterns working. I am looking for a more efficient way to do this than test each line for 6 0r 8 matches.

Any other ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T17:59:02+00:00Added an answer on May 29, 2026 at 5:59 pm

    I have two thought:

    (1) Your last approach of using if statements to first find the right regex to apply is like to be quite efficient. I’d recommend it.

    (2) You can compose regex’s like this:

    var pattern1 = @"abc";
    var pattern2 = @"def";
    var unionPattern = "((" + pattern1 + ")|(" + pattern2 + "))";
    

    This makes it much more readable.

    If you never want to find a match that spans lines you should split the file into lines first. That will improve efficiency because the regexes have smaller inputs and will backtrack less.

    If your matches span multiple lines but they always start after a new-line, you can you can split the string into chunks first like this:

    var chunks = Regex.Split(str, "((fc\d)|(fcip\d)|(port-channel-\d)));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a project that parses an incoming text file. I am
i have been working on this text extraction project of various file extensions, but
I'm working on a java project that will allows users to parse multiple files
While working a project tonight, I ended up using one .js resource file for
I have this project I'm working on where I want to parse an xml
Im working on SpaceViking project from Ray Wenderlich's Cocos2D Book and the project has
I'm working on my new project but I can't figure out how to add
I'm working on a personal project focusing on analysis of text in a database.
I'm working on a project where I have to take data from one source
Working on a project that parses a log of events, and then updates a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.