• possible "regsub/regexp" bug

    From aotto1968@21:1/5 to All on Thu Jun 30 10:53:59 2022
    Hi,

    I have the following regexp:

    "(?!\()([A-Z][a-z]+)(?!\))"

    and I want to match

    "MkObjectLogC"

    into:

    "(?:Mk)?(?:Object)?(?:Log)?C"

    using the code

    set match "MkObjectLogC"
    while {[regsub {(?!\()([A-Z][a-z]+)(?!\))} $match {(?:\1)?} match]} {}

    but the solution is:

    "(?:Mk)?(?:(?:(?:(?:(?:Ob)?j)?e)?c)?t)?(?:(?:Lo)?g)?C"

    the online regexp is ok:

    https://regex101.com/r/cWJrDK/1

    mfg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Schelte@21:1/5 to All on Thu Jun 30 12:40:39 2022
    On 30/06/2022 10:53, aotto1968 wrote:
    using the code

    set match "MkObjectLogC"
    while {[regsub {(?!\()([A-Z][a-z]+)(?!\))} $match {(?:\1)?} match]} {}

    but the solution is:

    "(?:Mk)?(?:(?:(?:(?:(?:Ob)?j)?e)?c)?t)?(?:(?:Lo)?g)?C"

    the online regexp is ok:

    That's because you repeatedly reprocess the result of the previous substitution. The online regexp does the processing in one go. If you do
    the same with regsub, you get the requested result:

    regsub -all {(?!\()([A-Z][a-z]+)(?!\))} $match {(?:\1)?} match


    Schelte.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From clt.to.davebr@dfgh.net@21:1/5 to All on Thu Jun 30 16:28:33 2022
    That's because you repeatedly reprocess the result of the previous >substitution. The online regexp does the processing in one go. If you do
    the same with regsub, you get the requested result:

    regsub -all {(?!\()([A-Z][a-z]+)(?!\))} $match {(?:\1)?} match


    Why are the (?!\() bits necessary?

    regsub -all {([A-Z][a-z]+) $match {(?:\1)?}

    seems to work

    Dave B

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Schelte@21:1/5 to clt.to.davebr@dfgh.net on Thu Jun 30 21:01:31 2022
    On 30/06/2022 18:28, clt.to.davebr@dfgh.net wrote:
    That's because you repeatedly reprocess the result of the previous
    substitution. The online regexp does the processing in one go. If you do
    the same with regsub, you get the requested result:

    regsub -all {(?!\()([A-Z][a-z]+)(?!\))} $match {(?:\1)?} match


    Why are the (?!\() bits necessary?

    They're not. But I tend to change as little as possible from the
    original code to focus on the problem at hand.

    Why do you start a new thread, instead of following up in the existing one?


    Schelte.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)