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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:24:40+00:00 2026-06-18T17:24:40+00:00

I am trying to write lex code which will take a string as input,

  • 0

I am trying to write lex code which will take a string as input, and parse through a long dictionary file to find the longest word in that dictionary which is made up of only the letters in that string. Each letter in the string can be used zero or more times, meaning the word “in” would be valid for “input”. Here is what I have so far:

%{
#include <stdio.h>
%}

%option noyywrap

%% 
[input]+ { 
          printf("This is the longest I think: %s\n", yytext);
         }

.|\n    {}
%%

int main(void)
{
    yylex();
    return 0;
}

However, this really does not do what I expect it to do. This code goes through and prints the matching portions of every word in the dictionary, so I get output like “i”, “iu”, “inu”, etc., and these obviously aren’t valid words. Anyone know how to fix this?

  • 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-18T17:24:41+00:00Added an answer on June 18, 2026 at 5:24 pm

    You could use the beginning-of-line and end-of-line markers as part of your regular expression to require that the entire line is matched, not just a part of it. Try changing your regex from [input]+ to

    ^[input]+$
    

    You will then need some separate logic to track the longest string you’ve found so far, but judging from the code you have above I think this more directly addresses your question at hand.

    Hope this helps!

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

Sidebar

Related Questions

I am trying to write lex code which will take an input and then
Trying to write a code that searches hash values for specific string's (input by
Trying to write a couple of functions that will encrypt or decrypt a file
I'm trying to write generic code that can lex any stream of characters (
I am trying to write a lex pattern that will allow me to recognize
I'm trying write a query to find records which don't have a matching record
Trying to write a byte[] to a file, which i think is working correctly
I've been trying write an application which will be able to connect to a
I'm currently trying write code that will maintain the sorting preference while changing page
I'm trying write a code that can the set property value through the lambda

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.