Finding string with "wild" characters in another string

P

Pawe³

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
 
E

Emmanuel Delahaye

Pawe³ said:
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.

Have a look to the third party 'regex' library. Google is your friend.
 
J

Jason Curl

Have a look for PCRE. This is very similar to Perl and is also free. It's
reasonably easy to use.
 
K

Keith Thompson

Emmanuel Delahaye said:
Have a look to the third party 'regex' library. Google is your friend.

A regex isn't necessarily what the OP is looking for; from his
description, it sounds more like Unix-style file globbing.

In a regular expression, '.' matches a single character, and '*' is a
suffix indicating zero or more occurrences of the preceding pattern.
In a glob, '?' corresponds to a regex '.', and '*' corresponds to a
regex '.*'.

comp.unix.programmer might be a good place to get more information.
 
M

Malcolm

Keith Thompson said:
A regex isn't necessarily what the OP is looking for; from his
description, it sounds more like Unix-style file globbing.
In particular, the difficulty of implementing a wildcard matcher bears no
comparison to the difficulty of writing a regular expression parser.

The wildcard matcher is also easier to use, and nine times out of ten as
powerful as you need.
 
P

Peter Nilsson

Pawe³ said:
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.

http://groups.google.com/[email protected]

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

Lookup fgets().
 
W

Wayne Rasmussen

what is the good C way of doing this? people seem to be assuming this is an O/S
question, but I think he is asking what if I have to implement such a thing. What
approach to take that isn't using someone else's libraries or some O/S feature.
After all, someone had to implement such a thing to create the library and O/S
feature.
 
R

Richard Bos

Wayne Rasmussen said:
what is the good C way of doing this?

[ This: reading lines from a file and searching them. ]

Using fgets() and sscanf(), despite Dan's insistence that they're worse
that gets(), abort(), and printf("You're a loser"). You'll find that his
opinions on the relative merits of fgets() and scanf() are somewhat
uncommon among the regulars.

Richard
 
D

Dan Pop

In said:
what is the good C way of doing this?

It depends on what *exactly* you want to do, when the input line is longer
than expected. But, no matter what you want to do, fgets() is the worst
way of doing it. Use either getc() or fscanf() instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top