Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Finding string with "wild" characters in another string
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Pawe  
View profile  
 More options Jul 9 2004, 5:36 am
Newsgroups: comp.lang.c++
From: "Paweł" <pa...@itproject.com.pl>
Date: Fri, 9 Jul 2004 11:36:52 +0200
Local: Fri, Jul 9 2004 5:36 am
Subject: Finding string with "wild" characters in another string
Hello!

I'm looking for efficient code or site where I can find code for finding one
string in another string. String which I search should have "wild"
characters like '?' for any one char and '*' for any string of characters.

I'm looking for way to effective getting string from text file and then
searching it like I write above.

Thanks in advance for any helps, notices or sites

--

Best regards
Paweł Chmielarz
----------------------------------
pa...@itproject.com.pl


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Harrison  
View profile  
 More options Jul 9 2004, 5:57 am
Newsgroups: comp.lang.c++
From: "John Harrison" <john_androni...@hotmail.com>
Date: Fri, 9 Jul 2004 10:57:38 +0100
Local: Fri, Jul 9 2004 5:57 am
Subject: Re: Finding string with "wild" characters in another string

"Paweł" <pa...@itproject.com.pl> wrote in message

news:cclos8$fb8$1@sunflower.man.poznan.pl...

> Hello!

> I'm looking for efficient code or site where I can find code for finding
one
> string in another string. String which I search should have "wild"
> characters like '?' for any one char and '*' for any string of characters.

> I'm looking for way to effective getting string from text file and then
> searching it like I write above.

> Thanks in advance for any helps, notices or sites

http://www.boost.org/libs/regex/doc/index.html

john


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roman Ziak  
View profile  
 More options Jul 9 2004, 9:05 am
Newsgroups: comp.lang.c++
From: "Roman Ziak" <ro...@nospam.com>
Date: Fri, 9 Jul 2004 09:05:48 -0400
Local: Fri, Jul 9 2004 9:05 am
Subject: Re: Finding string with "wild" characters in another string
"Paweł" <pa...@itproject.com.pl> wrote in message

news:cclos8$fb8$1@sunflower.man.poznan.pl...

> Hello!

> I'm looking for efficient code or site where I can find code for finding
one
> string in another string. String which I search should have "wild"
> characters like '?' for any one char and '*' for any string of characters.

> I'm looking for way to effective getting string from text file and then
> searching it like I write above.

> Thanks in advance for any helps, notices or sites

Hope this helps. I pulled it out of the project with some custom types
(e.g. char*) and changed them here to built-in types, but apologize if
it won't compile as is. The algorithm has been tested and is in production.
Unfortunately you will not get the found matched substrings as with
regular expressions, but is quite fast.

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 strcmp(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(*wild == *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(*wild == *text) {
                lasttext = text;        /* remember last good position */
                state = SYNC;           /* synchronized again */
            } else
                text++;
        }
    }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »