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

  • Home
  • SEARCH
  • 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 8370387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:54:02+00:00 2026-06-09T13:54:02+00:00

I have to parse this format using regexp in TCL. Here is the format

  • 0

I have to parse this format using regexp in TCL.
Here is the format

              wl -i eth1 country

              Q1 (Q1/27) Q1

I’m trying to use the word country as a keyword to parse the format ‘Q1 (Q1/27) Q1’.
I can do it if it is in a same line as country using the following regexp command.

   regexp {([^country]*)country(.*)} $line match test country_value

But how can i tackle the above case?

  • 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-06-09T13:54:03+00:00Added an answer on June 9, 2026 at 1:54 pm

    Firstly, the regular expression you are using isn’t doing quite the right thing in the first place, because [^country] matches a set of characters that consists of everything except the letters in country (so it matches from the h in eth1 onwards only, given the need to have country afterwards).

    By default, Tcl uses the whole string to match against and newlines are just ordinary characters. (There is an option to make them special by also specifying -line, but it’s not on by default.) This means that if I use your whole string and feed it through regexp with your regular expression, it works (well, you probably want to string trim $country_value at some point). This means that your real problem is in presenting the right string to match against.

    If you’re presenting lines one at a time (read from a file, perhaps) and you want to use a match against one line to trigger processing in the next, you need some processing outside the regular expression match:

    set found_country 0
    while {[gets $channel line] >= 0} {
        if {$found_country} {
            # Process the data...
            puts "post-country data is $line"
            # Reset the flag
            set found_country 0
        } elseif {[regexp {(.*) country$} $line -> leading_bits]} {
            # Process some leading data...
            puts "pre-country data is $leading_bits"
            # Set the flag to handle the next line specially
            set found_country 1
        }
    }
    

    If you want to skip blank lines completely, put a if {$line eq ""} continue before the if {$found_country} ....

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any tool that can parse/conver xml files to this format? I have
I have been trying to parse the bottom table on this site using different
I have a set of time in this format. 01:00:04 How can I adjust
I'm trying to parse this xml input using the bash utility xpath : <?xml
Possible Duplicate: How can I parse this JSON in Android? I have a requirement,
Normally the XML files I have to parse are like this: <row id=1> <title>widget<title>
I have string as abvd.qweqw.sdfs.a=aqwrwewrwerrew . I need to parse this string and get
I have a JSON which I get from web application. I try this parse
http://www.taxmann.com/TaxmannWhatsnewService/Services.aspx?service=gettopstoriestabnews This is my web service I have to parse and store all value
I have this JSON http://www.progmic.com/ielts/retrive.php that I need to parse. When I do it

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.