Is there something similar to a LIKE function in python? What I'm trying to accomplish is to search inside a string, if it finds specific criteria it sets another variable to a specific value.

In other scripting languages I have used a LIKE function to do this but I can't find anything comparable in Python.

Recommended Answers

All 6 Replies

Check out regular expressions in the re module.

The simplest functions to search a string are find() and index().

what functions in other languages did you use?

If it's like the like() function in VB, then you can do it with module re, which does have wildcard and characterlist patterns.

>>> string = "A simple example string."
>>> if 'example' in string:
	print 'the word \'%s\' is in: "%s"' % ('example', string)

	
the word 'example' is in: "A simple example string."
>>>

That's exactly what I needed! Thanks for all of your help!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.