Meaning of '(. * [^ \\\\])'

1

Looking at the configuration files of prestashop , I found a regular expression. I do not know if it's complete, it's used in prestashop\controllers\admin\AdminTranslationsController.php

define( '_PS_TRANS_PATTERN_', '(.*[^\\])' );

Does anyone know what it's for?

    
asked by Orici 09.05.2017 в 12:43
source

1 answer

3

I'll explain, but I do not recommend using it at all. It can be used:

  • To remove all "\" at the end of the line.

    For example, for the name of a folder, for example, converting "\Carpeta\Otra\" to "\Carpeta\Otra" . - Regex101

  • To match characters that do not have a bar at the end.

    For example, within another regular expression, if it is necessary to make sure that in the end it will not have a \ that escapes the next character (although it is a really bad way to do it). A case would be if we search for text in brackets, but we do not want a bar at the end of that text to serve as an escape from the bracket, as in:

    preg_match( '/\$array\[' . _PS_TRANS_PATTERN_ . '\]/',  $texto);
    
  • Regex:

    (.*[^\])
    

    Description:

    • (.*[^\]) - Parentheses, to capture the text that coincided with:
      • .* - Any number of characters
      • [^\] - Matches 1 character, any character that is not a \ .


    Be that as it may, there are better ways to get the same result. It's pretty ugly that expression.
    Do not use it as an example, nor for a new code.

        
    answered by 09.05.2017 в 12:56