LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-12-2016, 08:17 AM   #1
ahc_fan
Member
 
Registered: Jan 2009
Location: Seattle, WA
Distribution: Slackware64 14.2
Posts: 259

Rep: Reputation: 11
Python regular expression error


I have a file containing a list of installed packages, one per line. The method below should return True if a match is found in the file. However I get this error output. I guess there is an issue with concatenating strings in re.compile()? What gives?

Code:
	def package_is_installed(self, path):
		pkg_name = path.split("/")[1]
		pkg_search = re.compile(r"^" + pkg_name + r"-.*SBo")
		self.inst_file.seek(0)
		for line in self.inst_file:
			if pkg_search.search(line):
				return True
		return False

Last edited by ahc_fan; 02-12-2016 at 10:07 AM.
 
Old 02-12-2016, 08:52 AM   #2
ahc_fan
Member
 
Registered: Jan 2009
Location: Seattle, WA
Distribution: Slackware64 14.2
Posts: 259

Original Poster
Rep: Reputation: 11
Nevermind. Had to use re.escape():

Code:
pkg_search = re.compile(r"^" + re.escape(pkg_name) + r"-.*SBo")
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Regular expression question in python... zinon75 Programming 10 11-10-2015 11:31 AM
[SOLVED] Python Regular Expression for use with Meld lkraemer Programming 2 12-19-2012 08:08 PM
Python replace() with regular expression ! noony123 Programming 1 03-16-2011 03:58 AM
[SOLVED] Python regular expression, cant get it to work madsovenielsen Programming 2 08-23-2010 09:54 PM
Python - need help narrowing a regular expression rose_bud4201 Programming 2 10-30-2005 12:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration