jball037
jball037

Reputation: 1800

Finding matches in Django model without punctuation or spaces

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.

Upvotes: 1

Views: 476

Answers (2)

Nafiul Islam
Nafiul Islam

Reputation: 82560

This could be the regex:

John +B(\.)? +Smith

Upvotes: 1

jazz
jazz

Reputation: 2377

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.

Upvotes: 2

Related Questions