Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 02-18-2025, 03:30 AM
Ddadoo57 Ddadoo57 is offline problem with capturing group in findText/ReplaceWith Windows 11 problem with capturing group in findText/ReplaceWith Office 2021
Advanced Beginner
problem with capturing group in findText/ReplaceWith
 
Join Date: Feb 2023
Posts: 94
Ddadoo57 is on a distinguished road
Default

Thanks for the feedback, it's really appreciated!

Thanks for deleting the post in the other thread, I thought I had.

The texte variable is a Range and its content is set from an objDoc.content.

To tell you the truth, I process rtf files generated by DeepL where I correct any remaining punctuation errors. To do this, I process every punctuation mark in the document, checking that non-breaking spaces, single spaces, etc. are correctly placed before or after the punctuation, depending on the context of it. I also correct formatting errors specific to the formatting that must be respected.

The loop here comes from the fact that not all matches were processed. I have the same error whitout le loop

Code:
    texte.Find.ClearFormatting
    texte.Find.Replacement.ClearFormatting
    texte.Find.MatchWildcards = True
    texte.Find.Execute findText:="…([A-Za-zÀ-ÖØ-öø-ÿ0-9])", ReplaceWith:="… \1", Replace:=2

It would be easier to do the processing with regular expressions, but the problem was that I was losing the original formatting of the text contained in the rtf. In fact, I used to do this very well with just a few lines of code, but on plain text, my code was like this :
Code:
regex.Pattern = “(…)([A-Za-zÀ-ÖØ-öø-ÿ])”
regex.Global = True
text.Text = regex.Replace(text.Text, “$1 $2”)
Today, to avoid losing the formatting with a regex, I use this type of code, but not everything is processed as I'd like.

Code:
               regex.Pattern = “([A-Za-zÀ-ÖØ-öø-ÿ0-9])\.([A-Za-zÀ-ÖØ-öø-ÿ0-9])”
                regex.Global = True
                If regex.test(texte.Text) Then
                    Set objMatches = regex.Execute(text.Text)
                    For Each objMatch In objMatches
                        With texte.Find
                            .ClearFormatting: .Replacement.ClearFormatting: .MatchWildcards = False
                            .Text = objMatch.Value
                            .Replacement.Text = Left(.Text, 1) & “. “ & Right(.Text, 1)
                            .Wrap = wdFindContinue: .Execute Replace:=wdReplaceAll
                        End With
                    Next
                    Set objMatches = Nothing
                End If
In short, since February 13 or 14, 2025, after updating something, whether it's Windows 11 or Word or some other setting on the PC, I've had to modify some original code.

Have you tried in word itself by doing Ctrl+H, then check wildcards and paste in search field “^0133([A-Za-zÀ-ÖØ-öø-ÿ0-9])” and replace field “... \1” if you get the same error? I've tried on 2 computers for “...Hello” I get “...H ello”.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with capturing group in findText/ReplaceWith Find and Replace not capturing entire line Steve Kunkel Word VBA 7 04-22-2021 10:00 AM
problem with capturing group in findText/ReplaceWith Capturing numbered headings jbvalen Word VBA 5 05-04-2017 05:03 PM
problem with capturing group in findText/ReplaceWith Capturing Redirected URL with macro souravkp Word VBA 1 07-11-2015 09:34 PM
problem with capturing group in findText/ReplaceWith Capturing addresses into contacts lordnacho Outlook 1 11-01-2010 06:05 PM
time capturing aligahk06 Excel 0 04-18-2010 11:53 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:12 PM.


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