Skip to content

Regular expression variables #11

@GoogleCodeExporter

Description

@GoogleCodeExporter
An interesting feature of ruby is that certain regular expressions can modify 
and create new variables.

There are some restrictions which means it should rarely (never?) introduce a 
security risk.

"This assignment is implemented in the Ruby parser. The parser detects 
‘regexp-literal =~ expression’ for the assignment. The regexp must be a 
literal without interpolation and placed at left hand side." - 
http://www.ruby-doc.org/core-1.9.3/Regexp.html


Example code:

somevar = 'before'

input = 'after'
if /(?<somevar>.*)/ =~ input
  match = true
end

puts somevar

Original issue reported on code.google.com by Luke.Jah...@gmail.com on 23 Oct 2012 at 3:34

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions