Find, but Replace with mixed attributes

J

Jedumi

I'm getting close in my research, but can't yet find a way to:

Find for example:

(c.1949)

and Replace with

(-c-.1949)--

Where the 'c' only is italicized.

Once I get the code for this, I'll be able to adapt to other and mor
complex scenarios, I hope
 
P

Peter T. Daniels

You could Find the string

(c.

and Replace it with the contents of the Clipboard

^c

after you put on the clipboard

(c.

with the c italicized. (Assuming the dash at the end isn't part of
what you want inserted. If it is, then simply search for a longer
string and replace it with a longer string.)
 
P

Paul

I'm getting close in my research, but can't yet find a way to:
Find for example:
(c.1949)
and Replace with
(-c-.1949)--
Where the 'c' only is italicized.
Once I get the code for this, I'll be able to adapt to other and more
complex scenarios, I hope.

You can turn on wildcards and use some more advanced regular expression
operators in both the Find What and Replace With fields.

For example in the Find What, you could use \((c). ([0-9]{4})\)
and in the Replace With field, you could use (-\1-.\2)--

That would perform the desired replacement in your example.

Here's a breakdown of what the expressions are doing:

\( is the opening paren. It must be preceded by a backslash so that the
Find-Replace tool sees it as a literal paren.

(c) captures the 'c' so that it can be referenced in the Replace With
expression

([0-9]{4}) Searches for any single digit in the class '0-9' that is
repeated 4 times. This grouping is also captured with parentheses so
that it can be referenced in the Replace With expression.

\) Ssearches for a literal closing paren.

In the Replace With expression:

( inserts a parenthesis

\1 inserts the first captured group (the '(c)' in the Find What
expression).

\2 inserts the second captured group (the '([0-9]{4})' in the Find What
expression).

For more info, look here:
http://www.bokorlang.com/journal/15msw.htm

and here:
https://office.microsoft.com/en-us/...regular-expressions-advanced-HA102350661.aspx
 
P

Peter T. Daniels

I'm getting close in my research, but can't yet find a way to:
Find for example:
(c.1949)
and Replace with
(-c-.1949)--
Where the 'c' only is italicized.
Once I get the code for this, I'll be able to adapt to other and more
complex scenarios, I hope.

You can turn on wildcards and use some more advanced regular expression
operators in both the Find What and Replace With fields.

For example in the Find What, you could use \((c). ([0-9]{4})\)
and in the Replace With field, you could use (-\1-.\2)--

He doesn't want hyphens around the c, he wants the c to be italic.
(The dash after the date was probably part of the metadiscussion, not
what he wants to insert -- what function would it perform?)
That would perform the desired replacement in your example.

Here's a breakdown of what the expressions are doing:

\( is the opening paren. It must be preceded by a backslash so that the
Find-Replace tool sees it as a literal paren.

(c) captures the 'c' so that it can be referenced in the Replace With
expression

([0-9]{4}) Searches for any single digit in the class '0-9' that is
repeated 4 times. This grouping is also captured with parentheses so
that it can be referenced in the Replace With expression.

\) Ssearches for a literal closing paren.

In the Replace With expression:

( inserts a parenthesis

\1 inserts the first captured group (the '(c)' in the Find What
expression).

\2 inserts the second captured group (the '([0-9]{4})' in the Find What
expression).

For more info, look here:http://www.bokorlang.com/journal/15msw.htm

and here:https://office.microsoft.com/en-us/word-help/find-and-replace-text-by...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top