当前位置: 动力学知识库 > 问答 > 编程问答 >

ruby on rails - regex basic url expression

问题描述:

Hi I'm creating a regular expression (ruby) to test the beginning and end of string. I have both parts but can't join them.

Beginning of string

\A(http:\/\/+)

End of string

(.pdf)\z

How to join?

Bonus if it could validate in-between and accept anything (to avoid http://.pdf)

By the way, rubular http://rubular.com is a neat place to validate expressions

网友答案:

Use .+ to match any character except \n one or more times.

\A(http:\/\/+).+(\.pdf)\z

Should match http://www.stackoverflow.com/bestbook.pdf but not http://.pdf

分享给朋友:
您可能感兴趣的文章:
随机阅读: