Regex url

J

Jean-Francois

Hi,

I try to match the following url with one regex

/hello
/hello/
/hello/world
/hello/world/


world is a variable, I can put toto instead

Thanks !
 
M

MRAB

Hi,

I try to match the following url with one regex

/hello
/hello/
/hello/world
/hello/world/


world is a variable, I can put toto instead
The regex is:

^/hello(?:/(?:[a-z]+/?)?)$

Its meaning is:

start of string
characters "/hello"
optional:
character "/"
optional:
one or more:
one of:
"a" .. "z"
optional:
character "/"
end of string

If it's not what you want, you need to be more specific.
 
C

Corey Richardson

Hi,

I try to match the following url with one regex

/hello
/hello/
/hello/world
/hello/world/


world is a variable, I can put toto instead

Thanks !

What was the regex you tried, and where did it fail? I'm no re guru, but
here's my go at it:

"(/hello/?(%s)?/?)" % var

Interpreter session:
Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.<_sre.SRE_Match object at 0x7f53baf25c68>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,086
Latest member
ChelseaAmi

Latest Threads

Top