Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Matching The Beginning And Ending Of A String

DZone's Guide to

Matching The Beginning And Ending Of A String

·
Free Resource
Source: The Ruby Language @ Programming Ruby [phrogz.net]

 

  
\A
    Matches the beginning of the string.
\z
    Matches the end of the string.
\Z
    Matches the end of the string unless the string ends with a “\n”, in which case it matches just before the “\n”.
s = "Coderpath is a weekly podcast\n by Ruby developers" s[/\A/] => "" s[/[\A]+/] => nil s[/.*\A/] => "" s[/*\A/] SyntaxError: (irb):10: target of repeat operator is not specified: /*\A/ from /usr/bin/irb1.9.1:12:in `
' s[/\w+\A/] => nil s[/\A./] => "C" s[/\A\w+/] => "Coderpath" s.scan(/\A./) => ["C"] s[/.*\z/] => " by Ruby developers" s[/.*$/] => "Coderpath is a weekly podcast" s[/.*\Z/] => " by Ruby developers" s[/[^\Z]+/] => "Coderpath is a weekly podcast\n by Ruby developers" s[/[^\z]+/] => "Coderpath is a weekly podcast\n by Ruby developers" s[/\z/] => "" s[/.\z/] => "s"
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}