Select to view content in your preferred language

Add functions like REGEXEXTRACT or even basic substring matching extraction

190
0
01-09-2025 07:08 AM
Status: Open
Labels (1)
HildermesJoséMedeirosFilho
Occasional Contributor

In some scenarios, such as in public surveys where JavaScript cannot be used, a simple string search can become a rather cumbersome task.

Imagine the following situation:

  1. An offline survey.
  2. An open survey to anyone.
  3. Participants will scan a QR code.
  4. We need to extract a specific number from this QR code. A string search or regex extraction would suffice, but neither is available.


    My solution to this was a quite cumbersome....idea..
    HildermesJosMedeirosFilho_0-1736434719228.png

     

 

if(
  regex(substr(${codigo}, 0, 5), '^#EXT#$'),
  0,
  if(
    regex(substr(${codigo}, 1, 6), '^#EXT#$'),
    1,
    if(
      regex(substr(${codigo}, 2, 7), '^#EXT#$'),
      2,
      if(
        regex(substr(${codigo}, 3, 8), '^#EXT#$'),
        3,
        if(
          regex(substr(${codigo}, 4, 9), '^#EXT#$'),
          4,
          if(
            regex(substr(${codigo}, 5, 10), '^#EXT#$'),
            5,
            if(
              regex(substr(${codigo}, 6, 11), '^#EXT#$'),
              6,
              if(
                 regex(substr(${codigo}, 7, 12), '^#EXT#$'),
                7,
                if(
                   regex(substr(${codigo}, 8, 13), '^#EXT#$'),
                  8,
                  if(
                     regex(substr(${codigo}, 9, 14), '^#EXT#$'),
                    9,
                    if(
                       regex(substr(${codigo}, 10, 15), '^#EXT#$'),
                      10,
                      if(
                         regex(substr(${codigo}, 11, 16), '^#EXT#$'),
                        11,
                        if(
                           regex(substr(${codigo}, 12, 17), '^#EXT#$'),
                          12,
                          if(
                             regex(substr(${codigo}, 13, 18), '^#EXT#$'),
                            13,
                            if(
                               regex(substr(${codigo}, 14, 19), '^#EXT#$'),
                               14,
                               if(
                                 regex(substr(${codigo}, 15, 20), '^#EXT#$'),
                                 15,
                                 if(
                                   regex(substr(${codigo}, 16, 21), '^#EXT#$'),
                                   16,
                                   if(
                                     regex(substr(${codigo}, 17, 22), '^#EXT#$'),
                                     17,
                                     if(
                                       regex(substr(${codigo}, 18, 23), '^#EXT#$'),
                                       18,
                                       if(
                                         regex(substr(${codigo}, 19, 24), '^#EXT#$'),
                                         19,
                                         "Error #EXT# not found 20 Trys"
                                       )
                                     )
                                   )
                                 )
                              )
                            )
                          )
                        )
                      )
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  )
)​


And 

if(
  regex(substr(${codigo}, int(${extposition}) + 5, int(${extposition})+12), '^\d{3,5}#$'),
  substr(${codigo}, int(${extposition}) + 5, int(${extposition})+11),
  if(
    regex(substr(${codigo}, int(${extposition}) + 5, int(${extposition})+11), '^\d{3,5}#$'),
    substr(${codigo}, int(${extposition}) + 5, int(${extposition})+10),
    if(
      regex(substr(${codigo}, int(${extposition}) + 5, int(${extposition})+10), '^\d{3,5}#$'),
      substr(${codigo}, int(${extposition}) + 5, int(${extposition})+9),
      substr(${codigo}, int(${extposition}) + 5, int(${extposition})+8)
    )
  )
)​


To address this, introducing a string search function that can find specific patterns or text within a larger string would be ideal.

This function could take a target pattern (like a keyword, number, or regex) as input and efficiently locate or extract matching parts of the string.

Functions like REGEXEXTRACT or even basic substring matching would simplify the logic and make it easier to handle such scenarios without relying on additional libraries or advanced tools.

 

Tags (2)