I am trying to validate some string as below
er34:12:roo, #vaild
er34:12: # invalid
er34:12:foo\n #vaild
foo\n #valid
str.match(/(?<=\w+:\d+:)?\w+(?=[,\n])/)
I am trying to validate some string as below
er34:12:roo, #vaild
er34:12: # invalid
er34:12:foo\n #vaild
foo\n #valid
str.match(/(?<=\w+:\d+:)?\w+(?=[,\n])/)
Dear Arup,
Ruby and Perl doesn’t support non-deterministic (variable lenght)
lookbehind.
"Many regex flavors, including those used by Perl and Python, only
allow fixed-length strings. You can use literal text, character
escapes, Unicode escapes other than \X, and character classes. You
cannot use quantifiers orbackreferences. You can use alternation, but
only if all alternatives have the same length.
PCRE is not fully Perl-compatible when it comes to lookbehind. While
Perl requires alternatives inside lookbehind to have the same length,
PCRE allows alternatives of variable length. Each alternative still
has to be fixed-length.PHP, Delphi, R, and Ruby also allow
alternatives of different lengths in lookbehind."
Source: Regex Tutorial - Lookahead and Lookbehind Zero-Length Assertions
Best regards,
Abinoam Jr.
… so… you shouldn’t use \w+ only \w
Abinoam Jr.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs