1

I have many files with the many of the following forms:

export function foo(payload={}) {
  return { type: bar, payload };
}

I would like to do a regex-replace that removes the spaces between the brackets so that the above becomes (note the removed spaces in the return clause):

export function foo(payload={}) {
  return {type: bar, payload};
}

In regex-builder I can get matches with the following:

"{ \\(.*?\\) }"

But when I try to do any kind of regex-replace across the file, with a replace pattern like {\1} I get 0 matches.

Flummoxed.

  • 1
    .* matches any chars except newlines, which includes brace chars. (And please show exactly what you tried. That can help others help you.) – Drew Jan 7 '16 at 16:08
  • Maybe try: "{\\s+\\([^}]*\\)\\s+}" instead? – wvxvw Jan 7 '16 at 16:20
  • When you call an interactive regexp command, you should not specify double backslashes. They are used only in elisp strings where \\ means a backslash, \n means a newline etc. – Lindydancer Jan 7 '16 at 16:30
  • Not that this is your problem, but I don't think the non-greedy modifier ? helps you in this case. – InHarmsWay Jan 7 '16 at 23:38
1

First be sure that your cursor is before the region you want to work on or that you highlight it.

{ +\(.*\) +}

worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.