It actually depends on where the "." is in the Regexp. In your case it
is inside a Character Class "[]". So it is matching the "." character
explicitly. Since \w is shorthand for the [a-zA-Z] character class. It
is parsed as a character class instead of an escaped "w" character. So
you could actually change the character class to be %r|[-\w_./]|. No
need to further escape the "_", or "-" since it is at the beginning of
the class (That's for another reason though).

On Dec 19, 10:12 am, AlwaysCharging <goodg...@gmail.com> wrote:
> Yes, that did it.  Thank you.
> No idea how I try everything and overlook the simplest solution, duh.
>
> And, Thank you to everyone else that weighed in as well, definitely
> some other options to look into.
>
> Side note:  Anybody know why the period doesn't have to be escaped?
> Like just "." allows the dot to be input, as well as "\."
> So, [-\w\_\.\/] works just as [-\w\_.\/].  Why is this?
>
> On Dec 19, 3:41 am, frogstarr78 <frogstar...@gmail.com> wrote:
>
>
>
> > Have you tried escaping them "\/"?
>
> > On Dec 18, 11:01 pm, AlwaysCharging <goodg...@gmail.com> wrote:
>
> > > In my app, I allow users to submit urls.  They (of course) need the
> > > ability to submit urls with a forward slash, "/", but whats the
> > > regular expression to allow them to do that?
>
> > > I currently use:
>
> > > validates_format_of :url, :with => /^[-\w\_.]+$/i
>
> > > to only allow alphanumerics, dashes, underscores, and dots to prevent
> > > cross site scripting when I later reconstruct these urls, but I can't
> > > figure out how to allow "/" as well.
>
> > > Any ideas?

--

You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.


Reply via email to