0

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

this is a good option if you're sure it's always all or nothing. it won't match http://.pdf but it will match http://foo.pdfor even http:///.pdf basically as long as there is at least one character between the / and the . it will still pass.
I'm pretty sure you meant to escape the . in .pdf. Also, the grouping is unnecessary as well as the + after \/\/. No -1 though because I'm feeling generous.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.