T
T
Talyan2020-02-27 10:43:25
linux
Talyan, 2020-02-27 10:43:25

How to set the number of characters in a regular expression in sed?

This code works:

echo -e "123\n45\n678" | sed -r -e 's/([0-9]+)/замена/g'

But as soon as I specify the number of characters, the code does not work:
echo -e "123\n45\n678" | sed -r -e 's/([0-9](2-3))/замена/g'


I need to search for complex strings by a specific mask, while some strings may differ from each other in the mask by just the number of digits following each other. To do this, I need to specify the expected number of characters in the sed regular expression.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SOTVM, 2020-02-27
@flapflapjack

sed -r -e 's/([0-9] {2,3} )/replace/g'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question