Verbose regular expressions in PHP?

后端 未结 1 786
星月不相逢
星月不相逢 2021-01-20 02:52

Searching on php.net I was not able to find any support for verbose regular expressions in php. Is this my fault for not knowing how to search for it, or is it php\'s fault

相关标签:
1条回答
  • 2021-01-20 03:23

    You can also set 'expanded' mode modifier within the regex as long as its the first char past the
    delimiter.

    = '/(?x)
                         # A comment
         (               # (1 start), some capture
            . 
         )               # (1 end)
      /';
    

    And/Or, it should also be available within //x context

    '/
                       # A comment
       (               # (1 start), some capture
            . 
       )               # (1 end)
    /x';
    

    Or, you can freely move in/out of x-mode within the code

    '/((?x)            # (1 start), some capture
            .
           (?-x: A )   # ' A ' 
       )               # (1 end)
    /'
    
    0 讨论(0)
提交回复
热议问题