Higure
Higure

Reputation: 235

RegEx to match whitespaces in urls

I'm trying to write a regexp that allow me to match a dynamic URL in Django 1.5

The URL will be like this: /file/namefile/ but namefile may contain one or more whitespaces that are converted in %20.

For example: URL: file/fourth test/ is saw as file/fourth%20test/.

The % character doesn't allow me to use something like this: ^file/(\w)/$ of course.

I need a regex that match that expression whatver the number of spaces (I don't really care about security in this stage of the project) but, being a total beginner, I'm stuck.

Upvotes: 2

Views: 4064

Answers (1)

svoop
svoop

Reputation: 3454

Try this:

^file/((?:\w|%20)+)/$

The ?: prevents the inner () from creating a reference.

Upvotes: 2

Related Questions