Help with capturing with regexp
I have this list:
foo chef.rb baz
bar cucumber.rb bar
baz gem.rb foo
I want to capture all the names without .rb.
My current regexp looks like this:
/(开发者_高级运维[^\s](?:.)*?.(?:rb))/i
But it captures the .rb too.
How do I capture just the base name?
Thanks.
Use this regex instead:
/(\w*?)\.rb\s*.*/i
And your base-name will be in the 1st capture group.
See it on rubular.
This is a bit simpler: /(\S+).rb(?:$|\s)/
Any non-space chars followed by .rb followed by either the end of line or a space.
精彩评论