• Login
Community
  • Login

Encapsulating specific lines with angle brackets

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 3 Posters 1.7k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E
    Elnaz Kia
    last edited by Aug 10, 2021, 6:18 PM

    Hi all,
    I want to encapsulate every line that starts with @ with angle brackets (as in the following example). The files are in multiple sub-directories. I tried regex but it replaces the whole line with <@.*> instead of keeping the text. I would appreciate any help with this.

    <@Begin>
    <@Languages: zho>
    <@Participants: C0026 IDc0026 Student>
    <@ID: zho|corpus|C0026|0;00.00|male|||Student|||>
    <@Media: c0026c05ri1_2, audio>
    <@Transcriber: >
    <@Situation: introduction>
    *C0026: wo3 zai4 wo3 xue2 xiao4.
    *C0026: xian4 zai4 zai4 (…) dian4 nao3 lao3 shi1 de1 ban1.
    *C0026: he2 wo3 (.) zai4 NAME.
    <@End>

    P 1 Reply Last reply Aug 10, 2021, 6:22 PM Reply Quote 0
    • P
      PeterJones @Elnaz Kia
      last edited by Aug 10, 2021, 6:22 PM

      @Elnaz-Kia ,

      In the Search, you need to match something like <@(.*?)> where you put the captured text in a capture group (and make it capture as little as possible); in the Replacement, use $1 to refer to the capture group value. see official regex “capture groups” documentation in the manual

      1 Reply Last reply Reply Quote 0
      • G
        guy038
        last edited by guy038 Aug 10, 2021, 9:16 PM Aug 10, 2021, 9:11 PM

        Hello, @elnaz-kia, @peterjones and All,

        May be I’m completly wrong but there is what I understand :

        For any line, beginning with the @ character, @elnaz-kia wants to surround all its contents with two angle brackets !

        If so, the following regex S/R should work :

        • SEARCH (?-s)^@.+

        • REPLACE <$0>

        • Tick preferably the Wrap around option

        • Select the Regular expression search mode

        • Click on the Replace All button

        Voila !

        Best regards,

        guy038

        P 1 Reply Last reply Aug 10, 2021, 9:18 PM Reply Quote 1
        • P
          PeterJones @guy038
          last edited by Aug 10, 2021, 9:18 PM

          @guy038 ,

          I agree with your interpretation. I just didn’t see enough in my first reading to get that far.

          Because the original post didn’t show a “before” and “after” state, I missed the “every line that starts with @” portion. Since I didn’t see enough information, I gave a brief reply that introduced the concepts required, and linked to the appropriate reading for those concepts.

          But yes, doing it my way with the “every line that starts with @”, I would change my FIND to (?-s)^@(.*)$ and the full replacement would be <$1>.

          For @Elnaz-Kia ,

          The substitution escape sequences section of the same usermanual page briefly describes @guy038’s $0 notation and my $1 is described in the section on $ℕ in the document. Both are essentially equivalent, with @guy038 making use of the automatic “whole match” capture group and mine using an explicit capture group.

          1 Reply Last reply Reply Quote 1
          4 out of 4
          • First post
            4/4
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors