问题描述:

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

相关阅读:
Top