How to replace paired square brackets with other syntax with sed?

前端 未结 4 1617
无人及你
无人及你 2020-12-06 01:57

I want to replace all pairs of square brackets in a file, e.g., [some text], with \\macro{some text}, e.g.:

This is some [text].
Th         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-06 02:14

    The following expression matches the pattern [a-z, A-Z and space] and replaces it with \macro{}

    sed -e 's/\[\([a-zA-Z ]*\)\]/\\macro{\1}/g'
    

    In the expression the \( ... \) form a match group that can be referenced later in the substitution as \1

提交回复
热议问题