简体   繁体   English

正则表达式基本url表达式

[英]regex basic url expression

Hi I'm creating a regular expression (ruby) to test the beginning and end of string. 嗨,我正在创建一个正则表达式(ruby)以测试字符串的开头和结尾。 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 ) 如果可以在中间进行验证并接受任何内容, http://.pdf (避免使用http://.pdf

By the way, rubular http://rubular.com is a neat place to validate expressions 顺便说一句,rubular http://rubular.com是验证表达式的好地方

Use .+ to match any character except \\n one or more times. 使用.+ 匹配\\ n以外的任何字符一次或多次。

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

Should match http://www.stackoverflow.com/bestbook.pdf but not http://.pdf 应该与http://www.stackoverflow.com/bestbook.pdf匹配,但不能与http://.pdf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM