Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-21-2021, 09:11 AM
Steve Kunkel Steve Kunkel is offline Find and Replace not capturing entire line Windows 10 Find and Replace not capturing entire line Office 2019
Advanced Beginner
Find and Replace not capturing entire line
 
Join Date: May 2019
Location: Seattle area
Posts: 78
Steve Kunkel is on a distinguished road
Default Find and Replace not capturing entire line

Hi there. First a side-question: When I see "FNR" in the forum, does that mean find-and-replace?



Now the actual question: This is actually for a VBA project, but I'm testing it using the built-in FaR tool.

Given this text (notice 'space space' at the beginning of some lines)

EDIT!!! Forum is truncating the spaces!!!! Let me try something different.
Okay... Screenshot...

My setup is
Code:
wildcards = true.
find = "([ ]@)(<[!^l^13]{1,}>)"
'my intent is (first group = zero or more spaces)(second grp = one or more of anything but a hard or soft line return)
replace = "\1+ \2"


It would be nice if there were a way to specify "beginning of line/end of line," but that doesn't appear to be possible.

Any thoughts on this?
Reply With Quote
  #2  
Old 04-21-2021, 03:50 PM
macropod's Avatar
macropod macropod is offline Find and Replace not capturing entire line Windows 10 Find and Replace not capturing entire line Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

FNR - maybe.

Use:
Find = "^13[ ]@<"
Replace = "^&+ "
and:
Find = "(^13)([! ])"
Replace = "\1+ \2"
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-21-2021, 03:52 PM
Guessed's Avatar
Guessed Guessed is offline Find and Replace not capturing entire line Windows 10 Find and Replace not capturing entire line Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Is your aim to find where a line wraps rather than where it is forced?
And if so, do you then want to append a "+spacespace" at the end of the line?

This is going to impact the line wrap positions and be unlikely to result in what you were aiming at.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #4  
Old 04-21-2021, 05:48 PM
Steve Kunkel Steve Kunkel is offline Find and Replace not capturing entire line Windows 10 Find and Replace not capturing entire line Office 2019
Advanced Beginner
Find and Replace not capturing entire line
 
Join Date: May 2019
Location: Seattle area
Posts: 78
Steve Kunkel is on a distinguished road
Default

Thanks for the replies guys! I guess it helps if I attach the document. Macropod, I can't seem to get yours to work... I tried changing "^13" into "^l", but still no luck.

Regarding line wraps vs forced; I guess I'm not sure what the definitions of these are. They are not 'wraps' in the sense that the text got to the right edge, then got wrapped automatically by Word, but they are the wrap that you get if you use "^l" in the Replace box. I guess maybe that's a "line return" and the "^13"one is a "new paragraph?"

Anyway, as I look closer at my post, I think it's my first group "([ ]@)" that is the problem. I wanted it to be "zero or more spaces" but I realize now this it is "one or more spaces." In the world of regex (which I'm not an expert of!) you can tell the regex to capture a sub group if it's there, but still go ahead and capture the the other group even if it's not. I guess maybe that's not possible with Word(?) It's worth noting that I did try "([ ]{0,})" but that is apparently not valid.

So my goal is to make this as flexible as possible. Most of the time, it will just be applied to a list of items that don't have any spaces at the beginning of lines. But *sometimes* there might be items that have one or two spaces. In those cases, they will be interspersed with no-beginning-space items (like in the attached). Usually they will have the 'line return' ^l at the ends.

My current system is that I have a function
Code:
Sub DoFindClean(FindText As String, ReplaceText As String, vWrap As String, vWild As String)
  'This module gets called from the Text Cleaner code
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = FindText
        .Replacement.Text = ReplaceText
        .Forward = True
        .Wrap = vWrap
        .MatchWildcards = vWild
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
that gets called by a bunch of different subtools in my user form tool.

Among those tools is the thing I'm trying to troubleshoot.
Code:
Private Sub cmdLeftPad_Click()
    Call DoFindClean("([!^13]{1,})", (txtPadding.Value) & "\1", 0, 1)
End Sub
Private Sub cmdRightPad_Click()
    Call DoFindClean("([!^13]{1,})", "\1" & (txtPadding.Value), 0, 1)
End Sub
But I'm thinking that I might need to have a mulitstep bit of code rather than calling the function... Something like
Assess each line
If first char of line = space
Then first Find string.
Else second find string.

I actually had considered that, but I don't think that wdTextLine is an object.

On a related note: It would also be excellent if I could detect the second-to-the-left character of each line. That way, if the text is as below (no spaces at line starts), it could differentiate the main ALLCAPS ones and the Word Case sub-items, and process them differently.

Quote:
READING COMPREHENSION
Passage Comprehension
Reading Recall
MATHEMATICS
Applied Problems
Calculation
EDIT: The second bit of code in this post is from my current working set up. It only works if no lines start with a space though--otherwise it fails.
Attached Files
File Type: docx just testing.docx (14.3 KB, 7 views)

Last edited by Steve Kunkel; 04-21-2021 at 05:54 PM. Reason: added a thought
Reply With Quote
  #5  
Old 04-21-2021, 06:00 PM
macropod's Avatar
macropod macropod is offline Find and Replace not capturing entire line Windows 10 Find and Replace not capturing entire line Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

The reason it doesn't work is that your data are in table cells that terminate with end-of-cell markers, not paragraph breaks or line breaks. Your previous posts didn't even hint at that possibility. Indeed, content represented as 'READING COMPREHENSION: 66' suggested nothing more than the presence of a colon in the strings.

Use:
Find = "[ A-Z]@[!^13^l]{1,}"
Replace = "+ ^&"
and:
Find = "(+ )([ ]@<)"
Replace = "\2\1"
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 04-21-2021, 07:54 PM
Steve Kunkel Steve Kunkel is offline Find and Replace not capturing entire line Windows 10 Find and Replace not capturing entire line Office 2019
Advanced Beginner
Find and Replace not capturing entire line
 
Join Date: May 2019
Location: Seattle area
Posts: 78
Steve Kunkel is on a distinguished road
Default

Ugh... So sorry about that...
It *does* get applied to non-table raw text, I just forgot to convert the table to text before uploading the file. Fixed below.

Anyway, I think I can probably still apply your logic: Have it capture the entire line, regardless of the spaces at the beginning. Then a second pass swaps the "bullet string" and the spaces (if they exist). Good logic :- }

I will experiment more tomorrow -- Thanks again!
Attached Files
File Type: docx just testing.docx (13.2 KB, 7 views)
Reply With Quote
  #7  
Old 04-21-2021, 08:14 PM
macropod's Avatar
macropod macropod is offline Find and Replace not capturing entire line Windows 10 Find and Replace not capturing entire line Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Your latest attachment has line breaks, not paragraph breaks. F/R expressions in my previous post updated accordingly.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 04-22-2021, 10:00 AM
Steve Kunkel Steve Kunkel is offline Find and Replace not capturing entire line Windows 10 Find and Replace not capturing entire line Office 2019
Advanced Beginner
Find and Replace not capturing entire line
 
Join Date: May 2019
Location: Seattle area
Posts: 78
Steve Kunkel is on a distinguished road
Default

Thanks for moving this to the correct forum. I was able to edit your above find and replace definitions to use the value from my text box. The below code works perfectly and I'm able to simply call my above posted function, which is nice.

Code:
Private Sub cmdLeftPad_Click()
    Call DoFindClean("([ A-Z]@[!^13^l]{1,})", (txtPadding.Value) & "\1", 0, 1)
    Call DoFindClean((txtPadding.Value) & "([ ]@<)", "\1" & (txtPadding.Value), 0, 1)
End Sub
Private Sub cmdRightPad_Click()
    Call DoFindClean("([ A-Z]@[!^13^l]{1,})", "\1" & (txtPadding.Value), 0, 1)
End Sub
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and Replace not capturing entire line Find and Replace Line Spacing farisca Word 2 06-18-2020 04:02 PM
Find and Replace not capturing entire line Find / Replace hard Carriage Return with Line break. GreenBoy Word 2 03-11-2018 02:32 AM
Find/Replace in a selected cell(s), but across entire workbook ue418 Excel 1 12-21-2017 12:32 AM
Find and Replace not capturing entire line Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM
using find/replace on an entire directory? mzimmers Word 0 12-13-2010 12:05 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:58 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