Encapsulating specific lines with angle brackets



  • 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>



  • @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



  • 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



  • @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.


Log in to reply