#1
|
|||
|
|||
Find and replace text with wildcards
Hi,
How to find below red highlighted text and replace it using Wildcards With .Range.Find .ClearFormatting .Replacement.ClearFormatting .Text = "" .Execute Replace:=wdReplaceAll Three scenarios - 1) Text with Aphanumberic with special characters 2) Text is in second row and sometimes partial with 1st row and second row 3) There is no Vertical bar (|) to pin point specific text 1 73181500 SCREW (200 NOS) | AB_1234K123 2 73269099 PLATE (16 NOS) | PL_3617A026 3 73181500 0S1573 BOLT Last edited by arunchandar9; 06-27-2019 at 02:45 PM. |
#2
|
||||
|
||||
From your description, the first two can be processed with:
Find = [A-Z]{2}_[A-Z0-9]@> You will need to provide more detail about the 3rd item.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Hi,
It works well with first scenario whereas causing error with second 157 73079290 ADAPTER AS.-ELBOW 90 DEG (NON ELECTRICAL) (50 NOS) | PL_361 7A026 173 73079290 ADAPTER AS.-ELBOW 90 DEG (NON ELECTRICAL) (50 NOS) | PL_3617A026 Below is the code I'm using now. It's not finding above highlighted Text if it's partial with first and second row or in second row .Text = "([0-9]{1,})[!^13]@| ([A-Z]{2}_[A-Z0-9]@>)*^13" I know it's complicated. It's a system generated word reports Regarding 3rd Scenario, I need to find every third text of below contents 1 73181500 0L1352 BOLT 2 73181500 0S1573 BOLT 354 73181500 3215144 BOLT-WHEEL 330 85365020 2552751 SWITCH AS-START 331 40169990 2588917 SLEEVE-HOSE |
#4
|
||||
|
||||
The Find code I posted can't possibly cause an error. What may happen if you go splitting the text as your latest post indicates - but wasn't indicated in your first post, is that it may miss part of the relevant match. To overcome that you might use:
Find = [A-Z]{2}_[A-Z0-9^13]{8,9}>
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
||||
|
||||
For your third scenario, you might use:
Find = (<[0-9]@ [0-9]{8}) [A-Z0-9]{6,7}( [A-Z]@>) Replace = \1\2
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
Thank you so much!! It works like a charm!!
|
#7
|
|||
|
|||
Quote:
Thank you!! |
#8
|
||||
|
||||
The {8,9} specifies that the matched string is to be 8 or 9 characters long.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Quote:
I ran many macros with difference {n,m} values. There is no effect with mentioned lines. |
#10
|
||||
|
||||
Perhaps, then, your line breaks aren't paragraph breaks. For all I know they may be generated by tabs or manual line breaks.
Without actually seeing a document with some representative content, it can be difficult for anyone to diagnose the issue. Can you attach sub a document to a post ? You can do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
Sure!! Sure!!
Enclosed Mentioned lines in which I faced this issue. It's a 1000 pages word doc I captured these as an example for your visibility. |
#12
|
||||
|
||||
Not only are your 'PL_' and trailing strings like '3617A026' separated by a paragraph break but there's also a string of spaces (i.e. ' ') before the paragraph break. To fix that, do an ordinary Find/Replace, with:
Find = ^w^p Replace = ^p before the wildcard Find/Replace.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
Quote:
I hac mentioned below code to find it and still able to see paragraph break in it (actually it has reduced mentioned spaces) Do I need to mention again please? Enclosed file after running this code for your reference .Text = "^w^p" .Replacement.Text = "^p" .Text = "([0-9]{1,})[!^13]@| ([A-Z]{2}_[A-Z0-9^13]{8,9}>)*^13" |
#14
|
||||
|
||||
In your attachment, you've replaced the string of spaces before the paragraph break, plus the paragraph break, with a single non-breaking space and a manual line break. The Find/Replace expression I posted didn't cause that. As for your question about the code itself, there's no .Execute line and there's nothing to indicate whether you're using wildcards. That said, at least one of the expressions wouldn't work unless you change the .UseWildcards state.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#15
|
|||
|
|||
Quote:
Sorry for pressing you more on Weekend!! Code:
With wdDoc .ConvertNumbersToText (wdNumberAllNumbers) With .Range.Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Format = False .Wrap = wdFindContinue .MatchWildcards = True .Text = "^w^p" .Replacement.Text = "^p" .Execute Replace:=wdReplaceAll .Text = "([0-9]{1,})[!^13]@| ([A-Z]{2}_[A-Z0-9^13]{8,9}>)^13"^p" |
Tags |
wildcards, word macros |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Dissecting a hyperlink with Find Replace Wildcards | WeyldFalcon | Word | 4 | 11-15-2016 12:48 PM |
Using wildcards in Find/Replace to change font/case | angie450 | Word | 2 | 05-26-2016 11:09 AM |
Using wildcards how do I Find and Add to, not replace | Stargehzer | Word | 3 | 01-25-2016 09:14 PM |
Find & Replace: Wildcards (except this pattern) | tinfanide | Word | 6 | 01-26-2014 06:39 AM |
wildcards in find & replace to reverse word order | jeffk | Word | 3 | 11-11-2012 01:47 PM |