-2

Possible Duplicate:
How to use several string arguments in Python

In the code below I'm trying to search for the one of the following patterns

  1. href="any characters with one hypen in between except ?"
  2. href="any characters with one hypen in between and if any other hypen, comes after ? "

I'm having problem where a variable must be inserted within regular expression twice.

Code:

mlink=re.findall('href="(%s+/[a-zA-Z0-9]+-[a-zA-Z0-9?=]+)"|href="(%s+/[a-zA-Z0-9]+-[a-zA-Z0-9]+[?]+[a-zA-Z0-9-]*)"' % path,contents)

Also,
I'm getting not enough arguments for format string error..

Community
  • 1
  • 1
Vindhya G
  • 1,339
  • 2
  • 21
  • 46
  • (Also, don't forget to [*quote* input to regular expressions](http://stackoverflow.com/questions/280435/escaping-regex-string-in-python) or you'll end up with special characters!) –  Jan 24 '13 at 06:38
  • 2
    Put parens around `path, contents` – Volatility Jan 24 '13 at 06:38
  • It's fairly annoying to chase moving questions. Make sure the code posted is the *actual code* used that exhibits said errors .. -1 because [looking up the error message would have said what is wrong](http://stackoverflow.com/search?q=%5Bpython%5D+not+enough+arguments+for+format+string+error). –  Jan 24 '13 at 06:40
  • that is the code for which i m getting error and i have mentiion exact error that is displayed – Vindhya G Jan 24 '13 at 06:42
  • (The code was changed, hence "moving" .. anyway, follow the above links.) –  Jan 24 '13 at 06:42

1 Answers1

1

instead of the % format operator, you could use the string formatfunction to put a variable in a string more than once

e.g.

 >>> '   {0}  {1}  {0}  '.format('foo', 'bar')
 '   foo  bar  foo  '

(the question isn't really about regex's!)

David Lam
  • 4,689
  • 3
  • 23
  • 34
  • if i use format function it returns list of tuples i.e if first condition is satisfied second element will be empty... i want list of string ..can you help me on this.. – Vindhya G Jan 24 '13 at 07:05