1

I'm trying to match a string that is a GET from the URL, to a field in the database that is the same string without any punctuation or spaces. For example:

URL: http://www.mysite.com/JohnBSmith/

And the string I'm trying to match in the database is: "John B. Smith"

Can I do this with regex? One catch is that I don't know how many punctuation marks or spaces there will be.

How do I do this with Django? I want to write this in the form:

myVariable = MyModel.objects.filter(foo=bar)

Thank you in advance.

tereško
  • 57,247
  • 24
  • 95
  • 149
jball037
  • 1,656
  • 1
  • 14
  • 18

2 Answers2

2

I would recommend adding a new column to your table, a new field to your model, maybe a SlugField and to ensure that when you save your model instance that this field is updated. You could use for this purpose django-autoslug.

jazz
  • 2,323
  • 19
  • 23
1

This could be the regex:

John +B(\.)? +Smith

Games Brainiac
  • 75,856
  • 32
  • 131
  • 189