---
title: "Ruby 正则"
author: "samson7b"
date: "2012-06-14T22:25:10Z"
tags: []
categories: ["编程语言"]
slug: "ruby"
draft: false
lastmod: "2012-06-14T22:25:10Z"
id: 1561278
url: "https://samson7b.iteye.com/blog/1561278"
---

(?=re) matches re at this point but does not consume it - you can look

forward for the context of a match without affecting $&.

 

```
str ="red, white, and blue"
p str.scan(/[a-z]+(?=,)/) 
```

 the result is :

```
=> ["red","white"]
```