开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜