Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login

POZE MRRRR'S FORUM (VIEW ONLY)

Nu sunteti logat.
Nou pe simpatie:
deiutza20
Femeie
21 ani
Bacau
cauta Barbat
21 - 44 ani
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides / [WORD] Wildcard Replacement of Text (wildcard rules and examples) Moderat de TRaP, TonyTzu
Autor
Mesaj Pagini: 1
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2186
There are many sources out there that illustrate the use of wildcard find and replace in Word. Will add a few at the end of this post, as usual.

First, a fair WARNING! Do not hit the replace all button too quickly! Wildcard search, if not used properly, may result in loss of data. Better make a backup of your file first.

I've read this somewhere and it seems to be the best approach: before constructing a complex find and replace with wildcard, make sure you test each part separately.

* * * *

Source of the text below is a PDF I got while searching the net for how to express a "Section Break" when using wildcards.

Finding the Wild Side: An Introduction to Using Wildcard Find and Replace in Microsoft Word, Kate McKiernan, AMWA 2019


Wildcards are a powerful way to find and replace because they allow you to search for a pattern or formula instead of exact text. 

Because wildcards are so powerful (and so cryptic!), they are very easy to get wrong, often with absurd results. You will make mistakes. I make mistakes. It is completely normal. 

Do not hit “replace all” until you’re quite certain a pattern is working.

Wildcard Operators

Kate McKiernan kate@nonclinicaleditor.com

Examples from https://www.officetooltips.com/word_2016/tips/using_wildcards.html

• ? - Any single character.
For example, d?g finds dig, dog, and dug, but not drug and ridge.

• * - Zero or more characters: finds a word with the specified characters and zero or more characters in place of *.
For example, des*t finds descent, desert, destiny, dessert, and destruct and even excludes the, codes - to. (note the bold characters match across words)

• < - Beginning of the word.
For example, <tel finds telemarketing, telephone, and television, but not hotel and retell.

• > - End of the word.
For example, ion> finds aggravation, inspiration, and institution, but not ionic and bionomics.

• @ - Preceding one or more: finds one or more of the characters immediately preceding the @ sign.
For example, ^p@^t finds one or more paragraph break marks followed by a tab mark.

• [] - One of the specified characters.
For example, b[aeiu]t finds bat, bet, bit, and but, but not debt and boot.

• [-] - Any character from the range.
For example, [a-m]end finds bend, fend, lend, and mend (the first character in this case is a, m, or any letter between them), but not rend and end.

• [!] - Not: finds the text but excludes the characters inside the brackets.
For example, t[!ae]ll finds till and toll but not tall and tell.

• [!a-z] - Any single character with the exception of the ones in the range inside the bracket.
For example, m[!o-z]st finds mast and mist, but not most or must.

• {n} - Exact number of occurrences: finds the specified number of occurrences of the letter immediately before the {.
For example, to{2} finds too and tool but not to.

• {n,} - Minimum number of occurrences: adding a comma after the number tells Word to look for at least that number of occurrences.
For example, a{4,} finds four or more of the letter a in a row.

• {n,n} - Minimum and maximum number of occurrences.
For example, 10{2,3} finds 100 and 1000, but not 10.

• () - Expression: lets you "nest" search expressions within a search term.
For example, <(pre)*(ed)> finds presorted and prevented, but not repressed and precedent. Also lets you refer to that group (\1, \2, etc.)

• \ - “escape” tells Word to stop “thinking” in wildcards and search for the next character verbatim
For example, \? finds ? and \( finds (

• ^s – nonbreaking space (not only a wildcard character)

Examples

Note: use a space (press of a space bar) not [space] for these to work (instead of [space] put an actual space)

1.

Goal: capitalize all mentions of “day” ONLY IF followed by a number: day 5 -> Day 5
Find: [Dd]ay[space]([0-9])
Replace: Day^s\1
What’s happening: Find either an uppercase or lowercase “d” followed by space followed by a number. Replace with “Day” followed by nonbreaking space followed by whichever number we found before.

2.

Goal: put a nonbreaking space in “in vivo” without changing capitalization
Find: n[space]([Vv])ivo
Replace: n^s\1ivo
What’s happening: Find the letter “n” followed by a space followed by either an uppercase or lowercase “v” followed by “ivo”. Replace with the letter “n” followed by a nonbreaking space followed by whichever “v” we found before followed by “ivo”.

3.

Goal: Highlight all text in parentheses
Find: \(*\)
Replace: Format -> Highlight
What’s happening: Find an “escaped” open parenthesis followed by any string followed by an “escaped” close parenthesis. Replace with the same text but add highlighting formatting.

4.

Goal: Rearrange dates (lacking ordinals) 7 August 2001 -> August 7, 2001
Find: ([0-9]{1,2})[space](<[AFJMNSOD]*>)[space]([0-9]{4})
Replace: \2[space]\1,[space]\3
What’s happening: Find a number that is 1 or 2 digits (ie, a date), followed by a capital letter that months can start with followed by any number of non-space characters (ie, a month), followed by a space, followed by exactly four digits (ie, a year). Replace with the month word, followed by the day digits, followed by a comma, followed by the year.

5.

Goal: Rearrange dates (with ordinals to none) 7th August 2001 -> August 7, 2001
Find: ([0-9]{1,2})([dhnrst]{2})[space](<[AFJMNSOD]*>)[space]([0-9]{4})
Replace: \3[space]\1,[space]\4
What’s happening: The same as the previous example except it finds two letters after the date and removes them. Could be included into replace if desired: \3[space]\1\2,[space]\4


More sources on Find and Replace with wildcardds:

Video tutorial:




_______________________________________


pus acum 2 ani
   
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2186
Control Codes that may be used with the search/replace tool (source mentioned above:)

^1    In-line picture
^2    Auto referenced footnotes
^5    Annotation mark
^9    Tab
^11    New line
^12    Page or Section break
^13    Paragraph break / 'carriage' return
^14    Column break
^19    Opening field brace (when field braces are visible)
^21    Closing field brace (when field braces are visible)
?    Question mark
^?    Any single character (not valid in the Replace box)
^-    Optional hyphen
^~    Non-breaking hyphen
^^    Caret character
^#    Any digit
^$    Any letter
^&    Contents of 'Find What' box (Replace box only)
^+    Em dash  (not valid in the Replace box)
^=    En dash  (not valid in the Replace box)
^u8195    Em Space Unicode character value search (not valid in the Replace box)
^u8194    En Space Unicode character value search (not valid in the Replace box)
^a    Comment (not valid in the replace box) (Word 97-2000 only)
^b    Section break (not valid in the replace box)
^c    Replace with Clipboard contents (Replace box only)
^d    Field
^e    Endnote Mark (not valid in the Replace box)
^f    Footnote Mark (not valid in the Replace box)
^g    Graphic (In Line Graphics Only). In Word 2007 a forward slash / also appears to find in-line graphics. This appears to be an unintentional bug.
^l    New line -
^m    Manual Page Break
^n    Column break
^t    Tab -
^p    Paragraph Mark -
^s    Non-breaking space
^w    White space (space, non-breaking space, tab); not valid in the Replace box
^nnn    Where "n" is an ASCII character number

Note: ASCII codes below 128 were standardized a long time ago, before the introduction of Windows operating systems. The upper codes were used for OS-specific, localized, or vendor-specific stuff. When DOS code pages were replaced by Windows code pages, a leading zero was used to indicated the difference.
Thus ^32 and ^032 will both represent a space character, but ^147 will represent ô and ^0147 will represent “

^0nnn    See above (Produces ASCII on Macintosh).
^unnnn    Unicode character search where "n" is a decimal number corresponding to the Unicode character value.

Note: Instructions on how to identify the required decimal number are included at the end of this page.

Note:    To search for a specific field, such as an XE (Index Entry) field, use the following syntax: ^19 field name

Example 1.

There are many occasions when you are presented with blocks of text or numbers etc., where the order of the text is not what you might require in the final document. Swapping the placement of forename and surname as above is one such example - and don't forget you can add to the replacement, even when using bracketed replacements

e.g. you may wish John Smith to appear as Smith, John or, more likely, you may have a column of names in a table, where you wish to exchange all the surnames with all the forenames.

You could do them one at a time, but by replacing the names with wildcards, you can do the lot in one pass.

Let's then break up the names into logical sequences that can only represent the names.

At its simplest, we have here two words - John and Smith. They can be represented by <*>[space]<*> - where [space] is a single press of the spacebar.

Add the round brackets  (<*>)[space](<*>) and replace with \2[space]\1

Run the search on the column of names and all are swapped. Run it again and they are swapped back.

If you get it wrong, remember that Word's 'undo' function (CTRL+Z) is very powerful and has a long memory!

Example 2.

This could be the changing of UK format dates to US format dates - or vice versa.

7th August 2001 to August 7th, 2001

To give an example of how most of the wildcards could be used in one search sequence to find any UK date formatted above to its equivalent US format date, the following search pattern will do the trick:

[0-9]{1,2}[dhnrst]{2} <[AFJMNSOD]*>[0-9]{4}

Breaking it down [0-9] looks for any single digit number, but dates can have two numbers so to restrict that to two, we use the count function. We want to find dates with 1 or 2 numbers so

[0-9]{1,2}

Next bit is the ordinal 'th'

- Ordinals will be 'st' 'rd' or 'th' so identify those letters specifically:

[dhnrst]

There will always be two letters, so restrict the count to 2

[dhnrst]{2}

Next comes the space. You can insert a space [space]

The month always begins with one of the following capital letters - AFJMNSOD. We don't know how many letters this month has so we can use the blanket '*' to represent the rest. And we are only interested in that word so we will tie it down with <> brackets.

<[AFJMNSOD]*>

there's another space [space] followed by the year. The years here have four numbers so

[0-9]{4}

Finally add the round brackets to provide a logical breakup of the sequence

([0-9]{1,2}[dhnrst]{2})[space](<[AFJMNSOD]*>)[space]([0-9]{4})

and replace with

\2[space]\1,[space]\3

to re-order the sequence.

Example 3.

Assume you are parsing addresses and wish to separate the honorific from the name.

American usage puts a full stop (period) at the end ("Mr.", "Mrs.", "Dr.") while British usage often omits the full stop.

([DM][rs]{1,2})( )

will find Mr Mrs Dr

without the stop and

\1.\2

will put one in.

or vice versa

([DM][rs]{1,2}).

will find Mr. Mrs. Dr. with the stop and

\1

will take it out.

Further examples:

(*^13)\1\1 will match any sequence of three identical paragraphs,

(*^13)@ will match any number of replacement paragraphs. Replace with \1 to remove duplicates from a sorted list.

\<([!\<\>]@)\>[!\<\>]@\</\1\> will match any well-formed XML element including start-tag and end-tag

(“<p>some text</p>” or “<customer-name>John Smith</customer-name>”)

By creating logical sequences you can search for almost any combinations of characters.


_______________________________________


pus acum 2 ani
   
TRaP
Moderator

Inregistrat: acum 6 ani
Postari: 739
Example for numbers >= 10 =< 99:

[0-9][0-9]\.

Or:

(<[0-9]{2})([\.])

- replace number 2 with any number of digits you want

and

(<[0-9]{2})([\.])[\^13]

- colored part is for new paragraph

Source:


pus acum 1 an
   
TRaP
Moderator

Inregistrat: acum 6 ani
Postari: 739
Today I had a mixed search: wildcards + font formatting.
Wanted to count the occurrences and not replace anything.

1. Selected the colored text, then went to Font color - More colors - Custom and clicked OK to confirm (this adds a swatch under Recent Colors below the regular swatches)

2. Open the Find dialog, check Use wildcards, then click on More > >

3. Click on Format - Font - Font color and select the color from pt. 1 from under Recent colors, then click OK

4. In the Find what field add the desired wildcard search, eg. ([C][0-9]).([0-9])

5. Click on Reading Highlight - Highlight all. Now above the buttons and under the Find what field, a couple of sentences will appear with the first telling you how many items were highlighted.


pus acum 1 an
   
TRaP
Moderator

Inregistrat: acum 6 ani
Postari: 739
Search for C1, C2 etc. to C9, then C10 etc. to C20

Replace [space] with actual space.

C1-C9:

([C][0-9])[space]



C10-C20:

([C][0-9][0-9])[space]


pus acum 12 luni
   
TRaP
Moderator

Inregistrat: acum 6 ani
Postari: 739
Replace

a)some text
b)other text
...
z)last text

with

a) some text
b) other text
...

Find: ([a-z]\))
Replace: \1[space]

Remember, replace "[space]" with actual space.


pus acum 7 luni
   
TRaP
Moderator

Inregistrat: acum 6 ani
Postari: 739
The following searches and fixes this situation:

some text ,next text ,something

so the space is before the comma, and not after

Find: (\ )(\,)([a-z])
Replace: \2[space]\3

Between \2 and \3 there is an actual space character.


pus acum 7 luni
   
TRaP
Moderator

Inregistrat: acum 6 ani
Postari: 739
The following searches and fixes this situation:

some text,next text,something

so a comma between 2 words, without a space after the comma

Find: (\,)([a-z])
Replace: \1[space]\2


pus acum 7 luni
   
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2186
How to change case / capitalize letters:

I had some text similar to the following:

Start of sentence to end of sentence.
start of 2nd sentence end of second sentence.
start of 3rd sentence


So I need to capitalize the first letter of each sentence.

My find with wildcards is ([\.])^13([a-z])

This is how to capitalize first word of all sentences that have the syntax above:
1. Press Ctrl+F to display the Find tab of the Find and Replace dialog box.
2. Click the More button and select Use Wildcards
3. Click Find In and select Main Document
4. Click Reading Highlight and select Highlight All
5. Press SHIFT+F3 to turn lowercase letters to uppercase letters.

Done.

Source:


_______________________________________


pus acum 7 luni
   
Pagini: 1  

Mergi la