Pattern Matching in C - 
Author Message
 Pattern Matching in C -

Hi

I am looking for Pattern Matching in C.

bool IsMatch(char* szStr, char* szPattern)

where szPattern can be "[a-z][0-9]*?".  

The example he gave was something like:

bool IsMatch("This is a string", "This*st?ing")
would return true.

"badbadbadbad"
"bad*d"

should return true.

Can any one help me

-TIA
--



Fri, 30 Sep 2005 12:25:41 GMT  
 Pattern Matching in C -

Quote:

> The example he gave was something like:
> bool IsMatch("This is a string", "This*st?ing")
> Can any one help me

Who is "he"?  Are you supposed to implement this
function yourself, for example in a programming class?

In general this kind of pattern matching is normally
discussed in the context of the more powerful
"regular expression" matching, and there are
numerous example implementations.  One is Henry
Spencer's, which as I recall was published on one
chapter of "Sofware Solutions in C" (ed. by Dale
Schumaker) to which I also contributed some
chapters.  You can probably find several via a
Google search.
--



Sun, 02 Oct 2005 08:23:28 GMT  
 Pattern Matching in C -


# Hi
#
# I am looking for Pattern Matching in C.
#
# bool IsMatch(char* szStr, char* szPattern)
#
# where szPattern can be "[a-z][0-9]*?".  
#
# The example he gave was something like:
#
# bool IsMatch("This is a string", "This*st?ing")
# would return true.
#
# "badbadbadbad"
# "bad*d"
#
# should return true.

Well, these two examples don't use character ranges ([]). I know someone
who solved that with a one-liner. Look for the shell glob matcher at
http://ioccc.org/years-spoiler.html#2001

Regards,

        Jens
--
Jens Schweikhardt  http://www.schweikhardt.net/
SIGSIG -- signature too long (core dumped)
--



Sun, 02 Oct 2005 08:23:47 GMT  
 Pattern Matching in C -

Quote:
>I am looking for Pattern Matching in C.

Did you try reading the FAQ?  If not, why?!?

Dan
--
Dan Pop
DESY Zeuthen, RZ group

--



Sun, 02 Oct 2005 08:23:50 GMT  
 Pattern Matching in C -
Following up, I just ran across a function called "match"
in the source code for the "ansitape" utility which I found
somewhere on the Web.  Of course it recusively invokes
itself.
--



Sun, 02 Oct 2005 08:24:01 GMT  
 Pattern Matching in C -

Quote:

> I am looking for Pattern Matching in C.
> bool IsMatch(char* szStr, char* szPattern)
> where szPattern can be "[a-z][0-9]*?".  

There is no such functions in standard C library, but POSIX.2 defines
function fnmatch with following prototype

#include <fnmatch.h>

int
fnmatch(const char *pattern, const char *string, int flags);

Which must be avaliable in most UNIX systems.

--
Best Regards
Mikhail Vladimirov <vladimirow[at]mail.ru>
--



Sun, 02 Oct 2005 08:26:02 GMT  
 Pattern Matching in C -

Quote:

> Hi

> I am looking for Pattern Matching in C.

Try "man regexp"

-apm
--



Mon, 03 Oct 2005 14:52:59 GMT  
 Pattern Matching in C -
Here is the code I developed and used successfuly on many projects. It is
quite fast and effective. Use the same way as strcmp(). Enjoy.

int wildmatch(char* wild, char* text)
{
    enum { UNSYNC,SYNC,START };
    char *lastwild, *lasttext;      /* last synced position in CMP mode */
    unsigned state, size;           /* SEARCH mode(0), CMP mode otherwise */

    for(state=START; ; )
    {
        if(*wild == 0) {                /* is end of wildargs ? */
            if(state!=UNSYNC && *text==0) /* is there text in synced mode?
*/
                return 0;
            if(state == START)           /* there was no asterisk at all */
                return -1;
            /* compiler gives warning: possible use before definition */
            size = wild-lastwild;       /* size of the string */
            return stricmp(lastwild, lasttext+strlen(lasttext)-size);
        }

        if(*text == 0) {                /* is end of text ? */
            while(*wild=='*') wild++;   /* skip all asterisks */
            return *wild==0 ? 0 : 1;    /* wild is at the end - success */
        }

        if(state != UNSYNC)
        {
            /* sync is when texts are synchronized */
            if(*wild == '*')  {
                while(*wild=='*') wild++;/* skip all consequent asterisks */
                lastwild = wild;        /* remember last positions */
                lasttext = text;
                state = UNSYNC;         /* unsynchronize */
            } else
            if(toupper(*wild) == toupper(*text) || *wild == '?') {
                wild++;                 /* they are same, move to nexts */
                text++;
            } else {
                if(state == START)      /* they don't match (no wildcard) */
                    return *wild-*text;
                wild = lastwild;        /* not equal chars in CMP mode */
                text = ++lasttext;      /* go back to last good */
                state = UNSYNC;         /* unsynchronize */
            }
        }
        else
        {
            /* non-sync is looking first match */
            if(toupper(*wild) == toupper(*text)) {
                lasttext = text;        /* remember last good position */
                state = SYNC;           /* synchronized again */
            } else
                text++;
        }
    }

Quote:
}



Quote:
> Hi

> I am looking for Pattern Matching in C.

> bool IsMatch(char* szStr, char* szPattern)

> where szPattern can be "[a-z][0-9]*?".

> The example he gave was something like:

> bool IsMatch("This is a string", "This*st?ing")
> would return true.

> "badbadbadbad"
> "bad*d"

> should return true.

> Can any one help me

> -TIA
> --


--



Sat, 08 Oct 2005 00:34:30 GMT  
 Pattern Matching in C -

Quote:

> Here is the code I developed and used successfuly on many projects. It is
> quite fast and effective. Use the same way as strcmp(). Enjoy.

Can you please state all the include files that are needed?  Thx.

Quote:
> int wildmatch(char* wild, char* text)
> {
>     enum { UNSYNC,SYNC,START };
>     char *lastwild, *lasttext;      /* last synced position in CMP mode */
>     unsigned state, size;           /* SEARCH mode(0), CMP mode otherwise */

>     for(state=START; ; )
>     {
>         if(*wild == 0) {                /* is end of wildargs ? */
>             if(state!=UNSYNC && *text==0) /* is there text in synced mode?
> */
>                 return 0;
>             if(state == START)           /* there was no asterisk at all */
>                 return -1;
>             /* compiler gives warning: possible use before definition */
>             size = wild-lastwild;       /* size of the string */
>             return stricmp(lastwild, lasttext+strlen(lasttext)-size);
>         }

>         if(*text == 0) {                /* is end of text ? */
>             while(*wild=='*') wild++;   /* skip all asterisks */
>             return *wild==0 ? 0 : 1;    /* wild is at the end - success */
>         }

>         if(state != UNSYNC)
>         {
>             /* sync is when texts are synchronized */
>             if(*wild == '*')  {
>                 while(*wild=='*') wild++;/* skip all consequent asterisks */
>                 lastwild = wild;        /* remember last positions */
>                 lasttext = text;
>                 state = UNSYNC;         /* unsynchronize */
>             } else
>             if(toupper(*wild) == toupper(*text) || *wild == '?') {
>                 wild++;                 /* they are same, move to nexts */
>                 text++;
>             } else {
>                 if(state == START)      /* they don't match (no wildcard) */
>                     return *wild-*text;
>                 wild = lastwild;        /* not equal chars in CMP mode */
>                 text = ++lasttext;      /* go back to last good */
>                 state = UNSYNC;         /* unsynchronize */
>             }
>         }
>         else
>         {
>             /* non-sync is looking first match */
>             if(toupper(*wild) == toupper(*text)) {
>                 lasttext = text;        /* remember last good position */
>                 state = SYNC;           /* synchronized again */
>             } else
>                 text++;
>         }
>     }
> }



>>Hi

>>I am looking for Pattern Matching in C.

>>bool IsMatch(char* szStr, char* szPattern)

>>where szPattern can be "[a-z][0-9]*?".

>>The example he gave was something like:

>>bool IsMatch("This is a string", "This*st?ing")
>>would return true.

>>"badbadbadbad"
>>"bad*d"

>>should return true.

>>Can any one help me

>>-TIA
>>--


--



Sat, 15 Oct 2005 23:45:07 GMT  
 Pattern Matching in C -
On 29 Apr 2003 15:45:07 GMT in comp.lang.c.moderated, bagsmode

Quote:




>>>I am looking for Pattern Matching in C.

>>>bool IsMatch(char* szStr, char* szPattern)

>>>where szPattern can be "[a-z][0-9]*?".

>>>The example he gave was something like:

>>>bool IsMatch("This is a string", "This*st?ing")
>>>would return true.

>>>"badbadbadbad"
>>>"bad*d"

>>>should return true.

>>>Can any one help me

>> Here is the code I developed and used successfuly on many projects. It is
>> quite fast and effective. Use the same way as strcmp(). Enjoy.

>Can you please state all the include files that are needed?  Thx.

>>             return stricmp(lastwild, lasttext+strlen(lasttext)-size);

guess?

Thanks. Take care, Brian Inglis         Calgary, Alberta, Canada
--

    fake address                use address above to reply
--



Tue, 18 Oct 2005 15:27:30 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Regular Expressions/Pattern Matching/Unordered pattern

2. Pattern Matching Tool

3. Pattern Matching in C

4. Help, Pattern used in Regex.Matches(...)

5. pattern matching and string replacement

6. help with a fast pattern matching utility requested

7. Pattern Matching in execution time

8. pattern matching with the function glob.

9. Performance while regexp pattern matching

10. pattern matching in c

11. HTML scraping (WSDL HTML pattern matching)

12. Request for Sample Code in case sensitive pattern matching of string in C

 

 
Powered by phpBB® Forum Software