Issue while parsing Complex Regular expression in YAML file

563 vues
Accéder directement au premier message non lu

Pawan Kumar

non lue,
4 juin 2020, 01:46:3704/06/2020
à Ansible Project
Issue is coming while parsing the following regular expression

"^[a-zA-Z0-9-+.#$%&~*\/=?^_ '\"\\!]{9,430}$"


Tried other options like



"^[a-zA-Z0-9-+.#$%&~*\/=?^_ '\\\"\\!]{9,430}$"


'^[a-zA-Z0-9-+.#$%&~*\/=?^_ '\"\\!]{9,430}$'


Issues coming


  stderr: |-
    while scanning a double-quoted scalar
      in "<string>", line 373, column 56:
         ... ex: '^[a-zA-Z0-9-+.#$%&~*/=?^_ '"\!]{
9,430}$'
                                                                            ^
    found unknown escape character '!'
      in "<string>", line 373, column 58:
         ... : '^[a-zA-Z0-9-+.#$%&~*/=?^_ '"\!]{
9,430}$'
                                                                         ^

----------------------------------------------------------------------------------------------------


ERROR! Syntax Error while loading YAML.
  expected <block end>, but found '<scalar>'


The offending line appears to be:

context_regex: '''^[a-zA-Z0-9-+.#$%&~*\/=?^_ '\"\\!]{9,430}$'''
                                                                                                              ^ here


-----------------------------------------------------------------------------------------------------

ERROR! Syntax Error while loading YAML.
  found character '`' that cannot start any token


The offending line appears to be:


context_regex: ```^[a-zA-Z0-9-+.#$%&~*\/=?^_ '\"\\!]{9,430}$```
                          ^ here

-------------------------------------------------------------------------------------------------------------------

ERROR! Syntax Error while loading YAML.
  found character '`' that cannot start any token


context_regex: `^[a-zA-Z0-9-+.#$%&~*\/=?^_ '\"\\!]{9,430}$`
                          ^ here


-------------------------------------------------------------------------------------------------------------------


ERROR! Syntax Error while loading YAML.
  expected <block end>, but found '<scalar>'

context_regex: '^[a-zA-Z0-9-+.#$%&~*\/=?^_ \'\\\!]{8,240}$'
                                                                                     ^ here

-------------------------------------------------------------------------------------------------------------------

ERROR! Syntax Error while loading YAML.
  expected <block end>, but found '<scalar>'


context_regex: '^[a-zA-Z0-9-+.#$%&~*\/=?^_ \'\\!]{9,430}$'
                                                                                     ^ here
------------------------------------------------------------------------------------------------------------------

ERROR! Syntax Error while loading YAML.
  expected <block end>, but found '<scalar>'


context_regex: '^[a-zA-Z0-9-+.#$%&~*\/=?^_ \'\\\"\\!]{9,430}$'
                                                                                      ^ here


------------------------------------------------------------------------------------------------------------------

ERROR! Syntax Error while loading YAML.
  expected <block end>, but found '<scalar>'

context_regex: '^[a-zA-Z0-9-+.#$%&~*\/=?^_ \'\\"\\!]{8,240}$'

                                                                                          ^ here


-----------------------------------------------------------------------------------------------------------------------

ERROR! Syntax Error while loading YAML.
  expected <block end>, but found '<scalar>'


context_regex: '^[a-zA-Z0-9-+.#$%&~*\/=?^_ \'\"\\!]{9,430}$'
                                                                                   ^ here

-----------------------------------------------------------------------------------------------------------------------


ERROR! Syntax Error while loading YAML.
  found unknown escape character '^'


context_regex: "\\\^[a-zA-Z0-9-+.#$%&~*\/=?^_ '\"\\!]{9,430}$\\\"
                                ^ here


-----------------------------------------------------------------------------------------------------------------------------

ERROR! Syntax Error while loading YAML.
  found unknown escape character '!'


context_regex: "^[a-zA-Z0-9-+.#$%&~*\/=?^_ '\\\!]{9,430}$"
                                                                                     ^ here

------------------------------------------------------------------------------------------------------------------------------



Vladimir Botka

non lue,
4 juin 2020, 03:27:1204/06/2020
à Pawan Kumar,ansible...@googlegroups.com
On Wed, 3 Jun 2020 22:46:37 -0700 (PDT)
Pawan Kumar <pawa...@gmail.com> wrote:

> '^[a-zA-Z0-9-+.#$%&~*\/=?^_ '\"\\!]{9,430}$'

Try this

'^[a-zA-Z0-9-+.#$%&~*/=?^_''\"!]{9,430}$'

In "single-quoted style" only the single-quote must be escaped ('')
https://yaml.org/spec/1.2/spec.html#id2788097

For example (occurrences left out)

- debug:
msg: OK
loop: ['a', '+', '}']
when: item is match(context_regex)
vars:
context_regex: '^[a-zA-Z0-9-+.#$%&~*/=?^_''\"!]$'

gives

ok: [localhost] => (item=a) => {
"msg": "OK"
}
ok: [localhost] => (item=+) => {
"msg": "OK"
}
skipping: [localhost] => (item=})

HTH,

-vlado

--
Vladimir Botka

Vladimir Botka

non lue,
4 juin 2020, 03:46:2104/06/2020
à Pawan Kumar,ansible...@googlegroups.com
The backslash must be escaped too (\\). For example,

- debug:
msg: OK
loop: [' ', "'", '\', '"', '!', '}']

when: item is match(context_regex)
vars:
context_regex: '^[a-zA-Z0-9-+.#$%&~*/=?^_ ''\\"!]$'

gives

ok: [localhost] => (item= ) => {
"msg": "OK"
}
ok: [localhost] => (item=') => {
"msg": "OK"
}
ok: [localhost] => (item=\) => {
"msg": "OK"
}
ok: [localhost] => (item=") => {
"msg": "OK"
}
ok: [localhost] => (item=!) => {
Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message