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 8940741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:07:14+00:00 2026-06-15T11:07:14+00:00

I have a pattern that is given below to match an ipv4 address in

  • 0

I have a pattern that is given below to match an ipv4 address in the dotted decimal notation.

IPV4ADDRESS (([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3}))

and I use

%x S_rule S_dst_ip

<S_rule>(dst-ip){SPACE}   {

           BEGIN(S_dst_ip);

        }


<S_dst_ip>\{{IPV4ADDRESS}\}  {

       /*code to process the sring here.*/
     }

to match an input of the form

dst-ip {10.13.12.138}

Now I want to match

dst-ip { 10.13.12.138 } in addition to dst-ip {10.13.12.138}

I modify the IPV4ADDRESS defined above as follows

IPV4ADDRESS [ \t]*(([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3}))[ \t]*

However this modification doesn’t seem to match

  dst-ip { 10.13.12.138 } OR dst-ip {10.13.12.138}

Can someone point out the error in my code ?

  • 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-15T11:07:16+00:00Added an answer on June 15, 2026 at 11:07 am

    Since it ‘works for me’, I can’t tell you what’s wrong with your code as you’ve not shown an SSCCE (Short, Self-Contained, Correct Example). Here’s one:

    /*IPV4ADDRESS     (([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3}))*/
    IPV4ADDRESS [ \t]*(([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3}))[ \t]*
    SPACE [ \t]
    
    %x S_rule S_dst_ip
    
    %%
    
    %{
        BEGIN S_rule;
    %}
    
    <S_rule>(dst-ip){SPACE}   {
               BEGIN(S_dst_ip);
            }
    
    <S_dst_ip>\{{IPV4ADDRESS}\}  {
           printf("\n\nMATCH [%s]\n\n", yytext);
           BEGIN S_rule;
         }
    
    . { ECHO; }
    
    %%
    
    int main(void)
    {
        while (yylex() != 0)
            ;
        return(0);
    }
    
    int yywrap(void)
    {
        return 1;
    }
    

    Using a test data file based on text from your question:

    dst-ip {10.13.12.138}
    dst-ip { 10.13.12.138 } 
    dst-ip {10.13.12.138}
    dst-ip { 10.13.12.138 } OR dst-ip {10.13.12.138}
    

    The program above produces (some blank lines elided):

    MATCH [{10.13.12.138}]
    
    MATCH [{ 10.13.12.138 }]
    
    MATCH [{10.13.12.138}]
    
    MATCH [{ 10.13.12.138 }]
    
     OR 
    
    MATCH [{10.13.12.138}]
    

    If I had to guess what’s going wrong, I’d suspect that you’re missing the switch back to state S_rule after recognizing S_dst_ip (and possibly the opening %{ BEGIN S_rule; %} phrase too).

    I note in passing that this will accept {999.999.999.999} as an IPv4 address. However, it’s feasible to fix that with a more tightly controlled expression, and isn’t germane to your main problem.

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

Sidebar

Related Questions

I have a pattern that is given below to match an ipv6 address in
I have this module pattern that stores a bunch of vars. I want to
I have got this regex pattern that works with my current apache log format:
So, one problem pattern that I keep coming across and don't have a good
I have a function that uses Pattern#compile and a Matcher to search a list
I have seen some people in SO commenting that Singleton Pattern is an anti-pattern.
I have a WPF app that is using the MVVM pattern. Hooking up buttons
I have a bunch of python methods that follow this pattern: def delete_session(guid): conn
I have an object of some class that obeys the singleton pattern. I need
I have gwt-project that is comunication to database. Application design mvp pattern and view

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.