Reputation: 57611
I'm creating a web page by copy-pasting paragraphs of a Word document. When I copy-paste, the beginning of sentences is preceded by two spaces, which I'd like to replace globally by a single space. However, I would not like this to affect my indentation, which is also by two spaces.
I'm trying to do this by using Atom's 'search with regex' feature. I'm trying to enter the expression
<p>.+ .+</p>
However, this does not produce any matches:
There should be matches, though, as illustrated by the highlighted areas within the p
elements in a regular search for ' ':
Also, from a little experiment in the Python shell, this regular expression seems to match what I'm looking for:
In [8]: re.findall(r'<p>.+ .+</p>', ' <p>Foo Bar</p>')
Out[8]: ['<p>Foo Bar</p>']
It seems from Atom's documentation, though, that the search term should be a Javascript RegExp
expression. I tried from the docs (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions) to adapt this to Javascript, but so far no success. How can I make this search in Atom work?
Upvotes: 0
Views: 214
Reputation: 156
In the case of having <p>Foo Bar</p>
as the sample input, the following find and replace will work:
"Find in current buffer" = <p>(.+) (.+)</p>
"Replace in current buffer" = <p>$1 $2</p>
Upvotes: 2
Reputation: 48751
The highlighted spaces in your image is within a <p class="flow-text">
- that has a class attribute - and you are searching for <p>
which doesn't include attributes. You should do this:
<p[^>]*>.+ .+</p>
However this produces a single match which you have to use capturing groups to replace two spaces with one. You may want to try a more precise approach. Search for:
[ ]{2,}(?=(?:(?!<p[^>]*>).)*<\/p>)
and replace with a single space.
Upvotes: 2