Ruby RegEx to Match between . and :
I have this string: "51. some thing:"
and would like to extract just "some thing" using reg ex in ruby. Can anyone point me in the right direction to match between a 开发者_如何学编程. and a : and discard everything else?'51. some thing:'.sub /.*\. *([^:]*).*/, '\1'
=> "some thing"
This should do it:
(?<=\.).+?(?=:)
If you want to avoid leading and trailing spaces in the match, you can use this:
(?<=\.\s*)\S.*?(?=\s*:)
Edit: I just checked and noticed that Ruby doesn't support lookbehind, which is used here. Alternatively, you can use this and take the capture of the regex as result:
\.\s*(\S.*?)\s*:
精彩评论