html - Vim batch delete/replace XML tags, but not content -
i have set of xmls , want remove or replace of tags
ie) <name>john doe</name>
, want left john doe
or john doe,
thanks help
for exact textual match of <name>john doe</name>
, can use following :substitute
command:
:%s#<name>\(john doe\)</name>#\1#g
this capture name inside tag (assuming contents can different), , replace entire match first captured group (\1
).
for more information, :help :substitute
has details. learn how commands , navigate built-in :help
; comprehensive , offers many tips. won't learn vim fast other editors, if commit continuous learning, it'll prove powerful , efficient editor.
this basic substitution works in vim sed
. automated processing of multiple files, i'd prefer latter.
a stern warning parsing xml regular expressions
note xml rather complex format many equivalent representations. regular expressions not powerful enough correctly process possible variants. it's alright quick replacement, if know source document well-formed in particular format, , following inspection of results, wouldn't use automation , production. there better tools (e.g. xslt) job. see this answer thorough discussion.
Comments
Post a Comment