Need help with Find and Replace using Regular Expressions

T

tante.v

I'm trying to search for instances of "St" in the middle of a word
(uppercase S, lowercase t) so that I can use Find and Replace to
correct the casing (as in firSt, laSt). I've come up with the
following regular expression string which almost works:

[!(<)( )(")(')^13]St

It was necessary to add so many exclusions to prevent it from giving
me "St" at the beginning of a word or line, after initial quotes, etc.

So, this works well except that it highlights not just "St", but the
letter preceding it: "rSt", "aSt". This prevents me from using Find
and Replace to replace "St" with "st". I can't seem to get a wildcard
like
?st to work in the Replace box, so I'm stuck. What is it about my
regex string that says "return the letter preceding the string I'm
looking for too"?

Thanks in advance.
 
G

Graham Mayor

How about replace
([a-zA-Z])St
with
\1st
?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

tante.v

Wow...that works great, and it's a lot simpler than what I was doing.
Can you help me to understand what the syntax is saying, so I get a
better idea of how to use regex?

Is it:

search for lowercase (a to z) or uppercase (A-Z)...meaning some letter
precedes the St...?

And could you explain what \1st means?

Thanks a lot! This is going to make my work go much more quickly.


How about replace
([a-zA-Z])St
with
\1st
?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>



I'm trying to search for instances of "St" in the middle of a word
(uppercase S, lowercase t) so that I can use Find and Replace to
correct the casing (as in firSt, laSt). I've come up with the
following regular expression string which almost works:
[!(<)( )(")(')^13]St
It was necessary to add so many exclusions to prevent it from giving
me "St" at the beginning of a word or line, after initial quotes, etc.
So, this works well except that it highlights not just "St", but the
letter preceding it: "rSt", "aSt". This prevents me from using Find
and Replace to replace "St" with "st". I can't seem to get a wildcard
like
?st to work in the Replace box, so I'm stuck. What is it about my
regex string that says "return the letter preceding the string I'm
looking for too"?
Thanks in advance.- Hide quoted text -

- Show quoted text -
 
G

Graham Mayor

Wow...that works great, and it's a lot simpler than what I was doing.
Can you help me to understand what the syntax is saying, so I get a
better idea of how to use regex?

Is it:

search for lowercase (a to z) or uppercase (A-Z)...meaning some letter
precedes the St...?
yes

And could you explain what \1st means?

replace with the first bracketed item \1 and add st

See http://www.gmayor.com/replace_using_wildcards.htm


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


How about replace
([a-zA-Z])St
with
\1st
?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>



I'm trying to search for instances of "St" in the middle of a word
(uppercase S, lowercase t) so that I can use Find and Replace to
correct the casing (as in firSt, laSt). I've come up with the
following regular expression string which almost works:
[!(<)( )(")(')^13]St
It was necessary to add so many exclusions to prevent it from giving
me "St" at the beginning of a word or line, after initial quotes,
etc.
So, this works well except that it highlights not just "St", but the
letter preceding it: "rSt", "aSt". This prevents me from using Find
and Replace to replace "St" with "st". I can't seem to get a
wildcard like
?st to work in the Replace box, so I'm stuck. What is it about my
regex string that says "return the letter preceding the string I'm
looking for too"?
Thanks in advance.- Hide quoted text -

- Show quoted text -
 
T

tante.v

Wow...that works great, and it's a lot simpler than what I was doing.
Can you help me to understand what the syntax is saying, so I get a
better idea of how to use regex?
search for lowercase (a to z) or uppercase (A-Z)...meaning some letter
precedes the St...?
yes

And could you explain what \1st means?

replace with the first bracketed item \1 and add st

Seehttp://www.gmayor.com/replace_using_wildcards.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>




How about replace
([a-zA-Z])St
with
\1st
?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
(e-mail address removed) wrote:
I'm trying to search for instances of "St" in the middle of a word
(uppercase S, lowercase t) so that I can use Find and Replace to
correct the casing (as in firSt, laSt). I've come up with the
following regular expression string which almost works:
[!(<)( )(")(')^13]St
It was necessary to add so many exclusions to prevent it from giving
me "St" at the beginning of a word or line, after initial quotes,
etc.
So, this works well except that it highlights not just "St", but the
letter preceding it: "rSt", "aSt". This prevents me from using Find
and Replace to replace "St" with "st". I can't seem to get a
wildcard like
?st to work in the Replace box, so I'm stuck. What is it about my
regex string that says "return the letter preceding the string I'm
looking for too"?
Thanks in advance.- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -

Thanks very much. Your website is extremely helpful, too--I'm sure
I'll be referring to it often.

I appreciate the help!
 

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