How to identify values in a string

0

We are making validators of expressions which are loaded in a database. The challenge is to take that expression, for example:

Objeto.getNombreFuncion("123").getAttribute("Nombre_Etiqueta") && 
Objeto.getNombreFuncion("Otra_Etiqueta").getAttribute("Nombre_Etiqueta")

and separate everything that is between quotation marks, it should look something like this:

 123
    Nombre_Etiqueta
    Otra_Etiqueta
    Nombre_Etiqueta

We are thinking about using python, but any language is welcome. Thanks

    
asked by Giuliano Marinella 12.08.2018 в 00:05
source

2 answers

0

I think any language can give you a simple solution, for example with JavaScript.

The steps I would take would be:

  • Assign content in a variable
  • Make a split of the content so that it creates an array with the elements, taking as a symbol the quotes.
  • Create an array with the new values, with an interleaved jump of lines (that is, one line yes and the other no)
  • What it would be:

    <!DOCTYPE html>
    <html>
    
    <body>
      <button onclick="ObtenerDatos()">Procesar</button>
      <script>
         function ObtenerDatos() {
         var datos = 'Objeto.getNombreFuncion("123").getAttribute("Nombre_Etiqueta") && Objeto.getNombreFuncion("Otra_Etiqueta").getAttribute("Nombre_Etiqueta")';
         var lineas = datos.split('"');
         var resultado = [];
    
         for (i = 1; i < lineas.length; i += 2) {
           resultado.push(lineas[i]);
          }
    
         for (i = 0; i < resultado.length; i++) {
           console.log(resultado[i]);
         }
       }
     </script>
    </body>    
    </html>
    

    You can see it working here link

    Remember to open the console to see the results

        
    answered by 12.08.2018 / 00:37
    source
    0

    In Python it would be something like this:

    string = 'Objeto.getNombreFuncion("123").getAttribute("Nombre_Etiqueta") && Objeto.getNombreFuncion("Otra_Etiqueta").getAttribute("Nombre_Etiqueta")'
    
    datos = string.split('"')
    
    for i in range(1, len(datos), 2):
        print(datos[i])
    

    Thanks for the help!

        
    answered by 12.08.2018 в 02:59