2

Given the following string:

<Node type="java script">dataSetRow["Invoice Number"]</Node>
<Node type="java script">dataSetRow["Invoice Number 2"]</Node>

How would remove the space in between the brackets using regex in a text editor? For example, dataSetRow["Invoice Number"] would be come dataSetRow["InvoiceNumber"]. So far, the best I can do is match all the text between the brackets.

(?<=dataSetRow\[)(.*)(?=\])

However, I can't seem to match just the spaces so that I can remove them. Any help would be greatly appreciated.

Thanks

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
EasyComp
  • 63
  • 1
  • 6

2 Answers2

2

Here is a step-by-step instruction:

  1. Open Find and Replace dialog
  2. Check Use Grep
  3. In Search For, type (\[[^\]]*?)\s+
  4. In Replace With, type \1
  5. Click Replace All several times until no further replacements are performed (i.e. no matches are found).
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
1

I'm not sure what editor you're using - in vim I would do it like this:

:1,$ s/(\["\S*)\s+(\S*"\])/\1\2/

or something like that - I always have to remind myself when vim needs backslashes and when it doesn't like for the parens...

Peter Bowers
  • 3,063
  • 1
  • 10
  • 18
  • I can't seem to get it to work, but it might just be because I'm using TextWrangler instead of Vim. I'll keep playing around with it. Thanks for the suggestion! – EasyComp Mar 24 '15 at 23:28