Why does free-run mode stop the negative appearance from working?

Consider the following Ruby code:

/(?<!big )dog/.match('I have a big dog.')        # => nil

Now I turn on the free space mode:

/(?x)(?<!big )dog/.match('I have a big dog.')        # => #<MatchData "dog">

Why is this happening, and how can I turn on the free space mode without violating my negative distortions?

+4
source share
1 answer
/(?x)(?<!big )dog/.match('I have a big dog.')
#           ^

Please note that after bigyou have a space. Since this is an advanced mode, spaces are ignored.

You have several options :

  • Use a pattern, for example, \sor \p{Space}.
  • Use escaped whitespace e.g. \e.g. space preceded by backslash.
  • , [ ].

:

/(?x)(?<!big\s)dog/.match('I have a big dog.')
# => nil
+3

Source: https://habr.com/ru/post/1613756/


All Articles