0

I want to replace everything in .* with “.*” in the following regex expression. Can someone please help?

/((This).*(has).*(features).*)/gm

So for example: Original: This red car has many features that don’t work

Replacement: This “red car” has “many” features “that don’t work”

user2994871
  • 167
  • 2
  • 12
  • 1
    You should match and capture the unknown parts and then use backreferences to those group values. See `This\s+(.*\S)\s+has\s+(.*\S)\s+features\s*(.*)` => `This “$1” has “$2” features “$3”` [demo](https://regex101.com/r/QBCqWM/1). – Wiktor Stribiżew Nov 10 '20 at 16:57
  • @WiktorStribiżew this is also removing/omitting the next line. How do I exclude that? [demo](https://regex101.com/r/QBCqWM/2) – user2994871 Nov 10 '20 at 18:03
  • You are not testing against standalone strings, so replace `\s` with `\h` if you want to stay matching within a line, see [this demo](https://regex101.com/r/QBCqWM/3). – Wiktor Stribiżew Nov 10 '20 at 18:05

0 Answers0