Home > other >  Regular expressions: why match, both before and after combined cannot match
Regular expressions: why match, both before and after combined cannot match

Time:02-21

I use ruby regular expression matching, the process is as follows:

The front part:
Reg1={% r \ A (//(. +) \ n)? }
=>//A (\ \/\ n (. +))?
Reg1=~//";
\ n"=> 0
$2
=> ";"

The back part:
Reg2={\ % r A (-? \ d + ([, | | \ n] -? *) \ \ d +) z}
=>//A (-? \ d + ([, | | \ n] -? *) \ \ d +) z/
Reg2=~ 1; "" 3 "
=> 0

Together:
Reg={% r \ A (//(. +) \ n)? (-? [\ \ d + (2 | | \ n] -? *) \ \ d +) z}
=>//A (\ \/\ n (. +))? (-? [\ \ d + (2 | | \ n] -? *) \ \ d +) z/
Reg=~//"; \ n1. 3 "
=> Nil

Could you tell me why the front part and back part can match, separately and together but not match?

CodePudding user response:

Add that ruby is support for regular expressions reference:
'1 ad2=~/(\ d) AD \ 1/
=> Nil
'2 ad2=~/(\ d) AD \ 1/
=>
  • Related