By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,931 Members | 1,357 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,931 IT Pros & Developers. It's quick & easy.

Wild Card String Comparison

P: n/a
Is it possible to do a search for a wild card string in another string. For
example, I'd like to find "v*.dat" in a string called bingo. v must be
matched against only the first character in bingo, and not simply found
somewhere in bingo, as might be the case for "*v*.dat".
--
Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39 15' 7" N, 121 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>
Aug 28 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Aug 27, 8:49*pm, "W. eWatson" <notval...@sbcglobal.netwrote:
Is it possible to do a search for a wild card string in another string. For
example, I'd like to find "v*.dat" in a string called bingo. v must be
matched against only the first character in bingo, and not simply found
somewhere in bingo, as might be the case for "*v*.dat".
--
* * * * * * Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

* * * * * * * (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std.time)
* * * * * * * *Obz Site: *39 15' 7" N, 121 2' 32"W, 2700 feet

* * * * * * * * * * *Web Page: <www.speckledwithstars.net/>
Check:

http://docs.python.org/lib/string-methods.html
http://docs.python.org/lib/module-re.html
http://docs.python.org/lib/module-glob.html
http://docs.python.org/lib/module-fnmatch.html

~Sean
Aug 28 '08 #2

P: n/a
On Wed, Aug 27, 2008 at 8:49 PM, W. eWatson <no*******@sbcglobal.netwrote:
Is it possible to do a search for a wild card string in another string. For
example, I'd like to find "v*.dat" in a string called bingo. v must be
matched against only the first character in bingo, and not simply found
somewhere in bingo, as might be the case for "*v*.dat".
--
Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39 15' 7" N, 121 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>
--
http://mail.python.org/mailman/listinfo/python-list
Is this what you're looking for?

Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:16)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>x = 'the quick brown fox'
'the' in x
True
>>'qui' in x
True
>>'jumped' in x
False
>>>
If that doesn't meet your needs you may want to look at the re
module. But if you can avoid re's your likely better off.
--
Stand Fast,
tjg. [Timothy Grant]
Aug 28 '08 #3

P: n/a
Timothy Grant wrote:
On Wed, Aug 27, 2008 at 8:49 PM, W. eWatson <no*******@sbcglobal.netwrote:
>Is it possible to do a search for a wild card string in another string. For
example, I'd like to find "v*.dat" in a string called bingo. v must be
matched against only the first character in bingo, and not simply found
somewhere in bingo, as might be the case for "*v*.dat".
--
Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39 15' 7" N, 121 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>
--
http://mail.python.org/mailman/listinfo/python-list
Is this what you're looking for?
What's this?
-----------------
Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:16)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>x = 'the quick brown fox'
------------------
>>>'the' in x
True
>>>'qui' in x
True
>>>'jumped' in x
False

If that doesn't meet your needs you may want to look at the re
module. But if you can avoid re's your likely better off.
re module??
>
There are no wild cards in your examples. * is one wild card symbol?
begin*end means find "begin" followed by any string of characters until it
find the three letters "end".

"begin here now but end it" should find "begin here now but end"
"beginning of the end is the title of a book" should find "beginning of the end"
"b egin but end this now" should find nothing.
--
Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39 15' 7" N, 121 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>
Aug 28 '08 #4

P: n/a
Sean DiZazzo wrote:
On Aug 27, 8:49 pm, "W. eWatson" <notval...@sbcglobal.netwrote:
>Is it possible to do a search for a wild card string in another string. For
example, I'd like to find "v*.dat" in a string called bingo. v must be
matched against only the first character in bingo, and not simply found
somewhere in bingo, as might be the case for "*v*.dat".
--
Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39 15' 7" N, 121 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>

Check:

http://docs.python.org/lib/string-methods.html
http://docs.python.org/lib/module-re.html
http://docs.python.org/lib/module-glob.html
http://docs.python.org/lib/module-fnmatch.html

~Sean
I'll take a look.

--
Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39 15' 7" N, 121 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>
Aug 28 '08 #5

P: n/a
On Wed, Aug 27, 2008 at 10:00 PM, W. eWatson <no*******@sbcglobal.netwrote:
Timothy Grant wrote:
>>
On Wed, Aug 27, 2008 at 8:49 PM, W. eWatson <no*******@sbcglobal.net>
wrote:
>>>
Is it possible to do a search for a wild card string in another string.
For
example, I'd like to find "v*.dat" in a string called bingo. v must be
matched against only the first character in bingo, and not simply found
somewhere in bingo, as might be the case for "*v*.dat".
--
Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39 15' 7" N, 121 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>
--
http://mail.python.org/mailman/listinfo/python-list
Is this what you're looking for?
What's this?
-----------------
>>
Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:16)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>>>
x = 'the quick brown fox'

------------------
>>>>>
'the' in x

True
>>>>>
'qui' in x

True
>>>>>
'jumped' in x

False

If that doesn't meet your needs you may want to look at the re
module. But if you can avoid re's your likely better off.

re module??
>>
There are no wild cards in your examples. * is one wild card symbol?
begin*end means find "begin" followed by any string of characters until it
find the three letters "end".

"begin here now but end it" should find "begin here now but end"
"beginning of the end is the title of a book" should find "beginning of the
end"
"b egin but end this now" should find nothing.
--
Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39 15' 7" N, 121 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>
--
http://mail.python.org/mailman/listinfo/python-list
you definitely need the re module then.
--
Stand Fast,
tjg. [Timothy Grant]
Aug 28 '08 #6

P: n/a
In article <Jg******************@nlpi067.nbdc.sbc.com>,
W. eWatson <no*******@sbcglobal.netwrote:
>Is it possible to do a search for a wild card string in another string. For
example, I'd like to find "v*.dat" in a string called bingo. v must be
matched against only the first character in bingo, and not simply found
somewhere in bingo, as might be the case for "*v*.dat".
Aug 28 '08 #7

P: n/a
Cameron Laird wrote:
In article <Jg******************@nlpi067.nbdc.sbc.com>,
W. eWatson <no*******@sbcglobal.netwrote:
>Is it possible to do a search for a wild card string in another string. For
example, I'd like to find "v*.dat" in a string called bingo. v must be
matched against only the first character in bingo, and not simply found
somewhere in bingo, as might be the case for "*v*.dat".
.
.
.
Does this session leave any questions:

python
Python 2.4.4c0 (#2, Oct 2 2006, 00:57:46)
[GCC 4.1.2 20060928 (prerelease) (Debian 4.1.1-15)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>import re
>>pattern = "^v.*\.dat"
>>compiled = re.compile(pattern)
>>compiled.match("victory.dat")
<_sre.SRE_Match object at 0xb7da2c60>
>>ms = compiled.match("victory.dat")
>>ms.group()
"victory.dat"
>>compiled.match("avoid.dat")
>># Notice the return value of "None".
...
>>import sys
>>sys.exit()

?
Looks good. re = regular expressions.

--
Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39 15' 7" N, 121 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>
Aug 28 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.