Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-18-2019, 07:53 PM
abdan abdan is offline Using VB Regex feature, I tried to replace 'the' and 'this' with 'that' but got screwed Windows 10 Using VB Regex feature, I tried to replace 'the' and 'this' with 'that' but got screwed Office 2016
Novice
Using VB Regex feature, I tried to replace 'the' and 'this' with 'that' but got screwed
 
Join Date: Apr 2018
Posts: 4
abdan is on a distinguished road
Default Using VB Regex feature, I tried to replace 'the' and 'this' with 'that' but got screwed

I tried to replace 'the' and 'this' with 'that' by using VB Regex feature on Word with the applied strings (ie. document) having font size mostly 10 and 18 for titles, but it resulted in entire strings having font size 18, although the regex seems works correctly (I can't read well)

Sub Regex_Replace
Dim re As Object, match As Object, matches As Object
Set re = CreateObject("VBScript.RegExp")
With re
.Global = True
.IgnoreCase = True
.Pattern = "(th)(e|is)\b"
ActiveDocument.Range.Text = .Replace(ActiveDocument.Range.Text, "$1at")
End With


End Sub

I can't read the document now as it got messed up and screwed with crammed words with font size 18.
How to solve it?
Sincere help would really be appreciated
Reply With Quote
  #2  
Old 01-18-2019, 08:21 PM
macropod's Avatar
macropod macropod is offline Using VB Regex feature, I tried to replace 'the' and 'this' with 'that' but got screwed Windows 7 64bit Using VB Regex feature, I tried to replace 'the' and 'this' with 'that' but got screwed Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

You don't need RegEx - or even a macro - for that. A wildcard Find/Replace, with:
Find = <th[eis]{1,2}>
Replace = that
will do. That said, it's not apparent how your font sizes or reference to titles (both of which can be accommodated in a wildcard Find/Replace) have to do with what you're doing, as your code discloses nothing about that.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-18-2019, 09:13 PM
abdan abdan is offline Using VB Regex feature, I tried to replace 'the' and 'this' with 'that' but got screwed Windows 10 Using VB Regex feature, I tried to replace 'the' and 'this' with 'that' but got screwed Office 2016
Novice
Using VB Regex feature, I tried to replace 'the' and 'this' with 'that' but got screwed
 
Join Date: Apr 2018
Posts: 4
abdan is on a distinguished road
Default

How I avoid from messing around finding 'thes', 'thee', thie, etc.
Reply With Quote
  #4  
Old 01-18-2019, 09:38 PM
macropod's Avatar
macropod macropod is offline Using VB Regex feature, I tried to replace 'the' and 'this' with 'that' but got screwed Windows 7 64bit Using VB Regex feature, I tried to replace 'the' and 'this' with 'that' but got screwed Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

It's not as if those aren't valid words... so why would you expect to find them with that Find expression?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
regex

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using VB Regex feature, I tried to replace 'the' and 'this' with 'that' but got screwed Section numbering screwed up scorpio_oz Word 7 04-06-2016 06:02 AM
Macro help regex subspace3 Word VBA 1 10-15-2014 09:53 AM
Using VB Regex feature, I tried to replace 'the' and 'this' with 'that' but got screwed Convert RegEx to Word (Devanagari Font Find/Replace) gasyoun Word VBA 9 04-12-2013 04:15 PM
Using VB Regex feature, I tried to replace 'the' and 'this' with 'that' but got screwed 2007 recent update screwed up view abrad99 Office 5 05-07-2011 09:55 PM
Regex in Word: Replaced strings are in disorder chgeiselmann Word 0 04-26-2009 11:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:10 PM.


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