Skip to content
Advertisement

Using sed regex for string replacement

I am trying to replace a string in the config file. I would like to run something like this:

OS

(docker image php:8.1-apache-buster)

Debian GNU/Linux 10 (buster)

sed (GNU sed) 4.7 Packaged by Debian

Possible inputs:

JavaScript

Example output (any user given value):

JavaScript

Example cmd:

JavaScript

enter image description here

Joining regex with strings does not work here.

It works when I run string replace without any regex

JavaScript

This works only if the value of the post_max_size is set exactly to 2M. I would like to be able to make a change with regex regardless of the value set.

I searched the Internet and sed cmd docs but did not find anything which fits my use case.

Advertisement

Answer

You can match optional spaces with [[:space:]]*, the -E for extended-regexp and use group 1 noted as 1 followed by your replacement like 1128M

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement