How does Anchor \ z and \ G work in Ruby?

I am using Ruby1.9.3. I am new to this platform.

From doc I just got a surname with two anchorthat \zand \G. Now I have played a bit with \zto see how this works, since the definition (End or End of String) has confused me, I can’t understand what it means to say - from End. So I tried the following small snippets. But still unable to catch.

CODE

irb(main):011:0> str = "Hit him on the head me 2\n" + "Hit him on the head wit>
=> "Hit him on the head me 2\nHit him on the head with a 24\n"
irb(main):012:0> str =~ /\d\z/
=> nil

irb(main):013:0> str = "Hit him on the head me 24 2\n" + "Hit him on the head >
=> "Hit him on the head me 24 2\nHit him on the head with a 24\n"
irb(main):014:0> str =~ /\d\z/
=> nil

irb(main):018:0> str = "Hit1 him on the head me 24 2\n" + "Hit him on the head>
=> "Hit1 him on the head me 24 2\nHit him on the head with a11 11 24\n"
irb(main):019:0> str =~ /\d\z/
=> nil
irb(main):020:0>

Every time I got nilas output. So, how is the calculation for \z? what does it mean End? - I think that my concept took something wrong with the word Endin the document. So could someone help me understand the reason why this is happening?

\G. , , , \G ?

irb(main):029:0>
irb(main):030:0*  ("{123}{45}{6789}").scan(/\G(?!^)\{\d+\}/)
=> []
irb(main):031:0>  ('{123}{45}{6789}').scan(/\G(?!^)\{\d+\}/)
=> []
irb(main):032:0>

+3
2

\z . , 4 . , , . \z , .

:

/\d\z/

"4" :

"24"

/\d\z/

"4" "4" :

"24\n"

, , \G:
\G ( ) Java


: Real-World \G

. , , , ( ). , , . :

Foo, bar.baz: buz'fuzz * -/ | ^

"har" . "har" . , :

/(?<=^|\G\W)\w+\b(?<!har)/

rubular

, , 3 ('foo'), . , lookbehind , , , "har" .

. 1 - (',' - - lookbehind, ), 3 ('bar').

, "har" , lookbehind, . , .

:

foo
bar
baz
buz
fuzz
hoo

"har" (, , "har" ), , :

/(?!^)(?<=har\W|\G\W)\w+\b/

rubular

, "har" , ( , ). :

haz
fil
bil
bak

"har" , :

/\bhar\b|(?!^)(?<=\G\W)\w+\b/

rubular

:

har
haz
fil
bil
bak
+5

, , Regex? , Regex ruby?

.

Regexp

Regex -

Regex cheat sheet

, \G . , , . , , .

, . , .

+2

All Articles