How to use named expressions?

How to use named expressions?

5
NewbieNewbie
5

    May 05, 2020#1

    I have read the readme announcement and the Perl documentations, and I think I should be able to use named references.

    The target string is: next: 04:11:21
    The search string is: next: (?<nxt>\d{2}:\d{2}:\d{2})
    This is recognized as a valid regular expression.
    The replace string again: \1 works fine.
    I think, I should be able to do a replacement with a replace string like: again: \g{nxt}
    But that does not work. What am I doing wrong?
    I tried various combinations of \k as well.

    Thanks.

    19176
    MasterMaster
    19176

      May 05, 2020#2

      Hi, UE supports named groups in replace in this form:
      $+{nxt}

      BR, Fleggy

      6,688586
      Grand MasterGrand Master
      6,688586

        May 05, 2020#3

        Okay, Fleggy posted already how to reference a named capturing group in replace string. Thank you, Fleggy.

        So everything written below is just informative.

        The page Named Capturing Groups and Backreferences describes comprehensive which regular expression implementations in various applications and libraries support named capturing groups. But it is not written on this page if back-referencing a named group works only in search string or also in replace string on using Boost library.

        The currently latest Boost Perl Regular Expression Syntax documentation of Boost library 1.73.0 describes:
        These named subexpressions can be referred to in a backreference using either \g{NAME} or \k<NAME> and can also be referred to by name in a Perl format string for search and replace operations, or in the match_results member functions.
        But it is not clear for me if that means back-referencing a named group with \g{NAME} or \k<NAME> is supported also in replace string or just in search string of a find or replace.

        I know from tests made with UltraEdit for Windows v26.20.0.68 that named backreferences with \g{NAME} and \k<NAME> work in search strings with currently latest UltraEdit for Windows v26.20.0.68 as described on Boost documentation page, but not in the replace string.

        I don't know which Boost library version is compiled into UltraEdit v26.20.0.68. You have to ask IDM support by email if you want to know that for further examination of back-referencing named capturing groups in replace string with \g{NAME} or \k<NAME> and if that is supported by the Boost library at all and if yes, since which version of the library.
        Best regards from an UC/UE/UES for Windows user from Austria

        19176
        MasterMaster
        19176

          May 05, 2020#4

          Hi Mofi,

          it looks like UE uses Boost library v1.68 according to the UE Help. The topic Regular Expressions (Perl Style) refers to this link

          BR, Fleggy

          6,688586
          Grand MasterGrand Master
          6,688586

            May 05, 2020#5

            Yes, indeed. I could find in executable of UltraEdit the symbol string boost@@@re_detail_106800 with knowing to search for 68. Now I know for which string to search in each version of UltraEdit executable to identify the Boost library version compiled static into UltraEdit executable. Boost library version 1.68 is used since UltraEdit for Windows v26.00. UltraEdit for Windows v25.00 to v25.20 use boost library version 1.65.
            Best regards from an UC/UE/UES for Windows user from Austria

            5
            NewbieNewbie
            5

              May 05, 2020#6

              Many thanks for that Fleggy and Mofi for the https://www.regular-expressions.info/ link -- what a great resource
              Also, did I over look the $+{nxt} syntax in the help somewhere?  I looked again this morning, and still couldn't find it.

              19176
              MasterMaster
              19176

                May 05, 2020#7

                Well, few years ago I tried everything from https://www.regular-expressions.info/refreplacebackref.html and reported to IDM that $+{NAME} brings an invalid expression error. And IDM did his work :)

                BTW this is also very nice source: The world's most tyrannosaurical regex tutorial (my favourite one)

                5
                NewbieNewbie
                5

                  May 05, 2020#8

                  Both are now bookmarked.
                  I needed this to parse a long string with many groups.
                  Previously I had been running two successive regexes

                  Thanks again