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> -
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$1to 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 aroundoption -
Select the
Regular expressionsearch mode -
Click on the
Replace Allbutton
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
$0notation and my$1is 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.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login