Skip to content

Ruby Global $` (DollarBacktick)

☈king edited this page Jan 30, 2013 · 6 revisions

The $` global is the string to the left of the last successful match.

If you do this:

str = 'hello goodbye'; str[/good/]

Then this:

[ $`, $&, $' ]

Yields this:

[
    "hello ",
    "good",
    "bye"
]
Clone this wiki locally