Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-27-2022, 02:55 AM
Bachelar Bachelar is offline Regex to find space after two-letter words at the of the line and replace Windows 10 Regex to find space after two-letter words at the of the line and replace Office 2021
Novice
Regex to find space after two-letter words at the of the line and replace
 
Join Date: May 2022
Posts: 3
Bachelar is on a distinguished road
Default Regex to find space after two-letter words at the of the line and replace

Hi, y'all!




I hope you're doing well.



I've come to you to seek help with the following. I would like to use regex to find space after one- or two-letter words at the of every line – any line ending not only with paragraph mark or manual line-break – and replace that space (and only space, words should remain unchanged).


From my inquires, I've gathered that Word wildcards will not be able to perform the requested action – although if it is not true, I'm of course open for clarification. Thus, I want to use regex via VBScript.RegExp object. I think, I have the regex pattern
Code:
\b\w+\b\K\s+
(with the help of regex101), but I'm still unsure on that.

To conclude, I don't know how to put together a script to search and replace with regex and I'm not sure if it's possible to get the space after one- or two-letter words at the end of every line.



It seems weird, I know, and if you want I can explain why I would like a script like that in details.


As always, thank you in advance for any input.
Reply With Quote
  #2  
Old 05-28-2022, 04:00 PM
macropod's Avatar
macropod macropod is offline Regex to find space after two-letter words at the of the line and replace Windows 10 Regex to find space after two-letter words at the of the line and replace Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Bachelar View Post
I would like to use regex to find space after one- or two-letter words at the of every line – any line ending not only with paragraph mark or manual line-break – and replace that space (and only space, words should remain unchanged).
...
To conclude, I don't know how to put together a script to search and replace with regex and I'm not sure if it's possible to get the space after one- or two-letter words at the end of every line.
To begin with, Word does not work with lines - it works with paragraphs, etc. That said, for a workaround see:
https://www.msofficeforums.com/word-...cter-line.html

Moreover, it's far from apparent what you want to do with those spaces once you've found them.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-29-2022, 12:12 AM
Bachelar Bachelar is offline Regex to find space after two-letter words at the of the line and replace Windows 10 Regex to find space after two-letter words at the of the line and replace Office 2021
Novice
Regex to find space after two-letter words at the of the line and replace
 
Join Date: May 2022
Posts: 3
Bachelar is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
To begin with, Word does not work with lines - it works with paragraphs, etc. That said, for a workaround see:
https://www.msofficeforums.com/word-...cter-line.html

Moreover, it's far from apparent what you want to do with those spaces once you've found them.

Apologies for not being clear. What I intend to do with found spaces is to replace them with non-breaking spaces.


I've also read the thread you linked and found it useful. I know that what I want can be achieved – at least somewhat – with Find/Replace. The problem with this approach is that it can only replace spaces after all one- or two-letter words, which breaks formatting.
Reply With Quote
  #4  
Old 05-29-2022, 07:03 AM
macropod's Avatar
macropod macropod is offline Regex to find space after two-letter words at the of the line and replace Windows 10 Regex to find space after two-letter words at the of the line and replace Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

So what is the point of dragging those words to the next line? You also need to be aware that any subsequent edits to the document are liable to mess up the affected paragraphs.

The link I posted also shows how one might approach finding line ends without Find/Replace.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and Replace and add colon and space falcios Word 2 07-28-2021 04:38 AM
Is there a way to only find the first letter of each line? (Word 97) Genericname1111 Word 4 09-11-2019 06:26 PM
Regex to find space after two-letter words at the of the line and replace Find and Replace with space cheech1981 Word 3 03-29-2017 02:33 PM
Regex to find space after two-letter words at the of the line and replace Find and replace with a macro, problem with letter case garcanrya Word VBA 2 01-10-2014 05:40 AM
Regex to find space after two-letter words at the of the line and replace Convert RegEx to Word (Devanagari Font Find/Replace) gasyoun Word VBA 9 04-12-2013 04:15 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:07 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft