正则表达式规范中的某些语法问题

问题描述

我一直收到这个非常烦人的错误

E: Error parsing configuration files:
    - routes: Error loading file: while parsing a quoted scalar
          in ".magento/routes.yaml",line 14,column 1
        found unkNown escape character
          in ".magento/routes.yaml",column 31

我的文件非常简单。请在下面找到它:

# The routes of the project.
#
# Each route describes how an incoming URL is going to be processed.

    #"http://{default}/":
    #    type: upstream
    #    upstream: "mymagento:PHP"
    
    
        http://{default}/:
            type: upstream
            redirects:
            paths:
        "^/catalogsearch/result((/)|(/\?)|(/\?[a-z])|(/\?[a-z]=))?$": { to: "https://www.example.com/",regexp: true }

我尝试使用双引号和单引号,并且还尝试使用\/来转义第14行第1列

我不确定我做错了什么,但在这一点上我正在失去情节。在这里需要帮助。预先感谢。

# The routes of the project.
#
# Each route describes how an incoming URL is going to be processed.

#"http://{default}/":
#    type: upstream
#    upstream: "mymagento:PHP"




   

    http://{default}/:
    type: upstream
    redirects:
    paths: ^/catalogsearch/result((/)|(/\\?)|(/\\?[a-z])|(/\\?[a- 
    z]=))?$ : { to: https:///www.example.com/,regexp: true }

解决方法

反斜杠用于在yaml中转义,因此必须用另一个反斜杠将其转义。将\替换为\\,并且不要在值周围使用引号:

paths: ^/catalogsearch/result((/)|(/\\?)|(/\\?[a-z])|(/\\?[a-z]=))?$

您的yaml语法对我来说是错误的或陌生的。我怀疑应该是:

http:
    type:      upstream
    redirects:
    paths:     ^/catalogsearch/result((/)|(/\\?)|(/\\?[a-z])|(/\\?[a-z]=))?$
    to:        https://www.example.com/
    regexp:    true