Regular expression ?{n,m} not working

H

Hagop

My Microsoft Word 2003 document contains the following:

# aa $
# bb $
# AA!AA $
# BB.BB $
# aaaaaaaaaaaaaa $
# bbbbbbbbbbbbbb $

My search regular expression is "# ?{1,10} $"

Word is finding all these lines as matching my search expression. It should
not find the last two lines, as the number of characters between the # and $
are more than 10.

If I change the regular expression to "# [A-z]{1,10} $" then it finds the
first two lines but not the 3rd and 4th.

This seems like a software bug to me. Can anybody else confirm this?
 
P

PamC via OfficeKB.com

Wow. That gets everything in the extended ASCII set. Thanks so much. I've
put it into my tips file and will be modifying and testing some of my search
strings very soon. What I don't remember are the differences in what ?, @,
and * do. Can you tell me or point me to a link?

PamC

Hi Hagop,

Try:
# [\!-ÿ]{1,10} $
My Microsoft Word 2003 document contains the following:
[quoted text clipped - 15 lines]
This seems like a software bug to me. Can anybody else confirm this?
 
H

Hagop

Click on the "?" help button on the Word search window and expand the topic,
"Wildcards for items you want to find and replace" for this:

Any single character
Type ?
For example, s?t finds "sat" and "set".

Any string of characters
Type *
For example, s*d finds "sad" and "started".

One or more occurrences of the previous character or expression
Type @
For example, lo@t finds "lot" and "loot".

PamC via OfficeKB.com said:
Wow. That gets everything in the extended ASCII set. Thanks so much. I've
put it into my tips file and will be modifying and testing some of my search
strings very soon. What I don't remember are the differences in what ?, @,
and * do. Can you tell me or point me to a link?

PamC

Hi Hagop,

Try:
# [\!-ÿ]{1,10} $
My Microsoft Word 2003 document contains the following:
[quoted text clipped - 15 lines]
This seems like a software bug to me. Can anybody else confirm this?
 
H

Hagop

Okay. That (kind of) worked.

I failed to mention in my example that text I want to match may contain
spaces. This is only matching one word between the # and the $.

macropod said:
Hi Hagop,

Try:
# [\!-ÿ]{1,10} $

--
Cheers
macropod
[MVP - Microsoft Word]


Hagop said:
My Microsoft Word 2003 document contains the following:

# aa $
# bb $
# AA!AA $
# BB.BB $
# aaaaaaaaaaaaaa $
# bbbbbbbbbbbbbb $

My search regular expression is "# ?{1,10} $"

Word is finding all these lines as matching my search expression. It should
not find the last two lines, as the number of characters between the # and $
are more than 10.

If I change the regular expression to "# [A-z]{1,10} $" then it finds the
first two lines but not the 3rd and 4th.

This seems like a software bug to me. Can anybody else confirm this?
 
G

Graham Mayor

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

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Wow. That gets everything in the extended ASCII set. Thanks so
much. I've put it into my tips file and will be modifying and
testing some of my search strings very soon. What I don't remember
are the differences in what ?, @, and * do. Can you tell me or
point me to a link?

PamC

Hi Hagop,

Try:
# [\!-ÿ]{1,10} $
My Microsoft Word 2003 document contains the following:
[quoted text clipped - 15 lines]
This seems like a software bug to me. Can anybody else confirm this?
 
P

PamC via OfficeKB.com

Thanks, I thought I remembered seeing something about the differences in how
they work with {} ranges. I guess not. ...Still trying to figure out why
the OP's search doesn't work.

PamC
Click on the "?" help button on the Word search window and expand the topic,
"Wildcards for items you want to find and replace" for this:

Any single character
Type ?
For example, s?t finds "sat" and "set".

Any string of characters
Type *
For example, s*d finds "sad" and "started".

One or more occurrences of the previous character or expression
Type @
For example, lo@t finds "lot" and "loot".
Wow. That gets everything in the extended ASCII set. Thanks so much. I've
put it into my tips file and will be modifying and testing some of my search
[quoted text clipped - 13 lines]
 
M

macropod

OK,

Try:
# ??{1,8}? $

--
Cheers
macropod
[MVP - Microsoft Word]

PS: I agree that, intuitively, '# ?{1,10} $' should work.


Hagop said:
Okay. That (kind of) worked.

I failed to mention in my example that text I want to match may contain
spaces. This is only matching one word between the # and the $.

macropod said:
Hi Hagop,

Try:
# [\!-ÿ]{1,10} $

--
Cheers
macropod
[MVP - Microsoft Word]


Hagop said:
My Microsoft Word 2003 document contains the following:

# aa $
# bb $
# AA!AA $
# BB.BB $
# aaaaaaaaaaaaaa $
# bbbbbbbbbbbbbb $

My search regular expression is "# ?{1,10} $"

Word is finding all these lines as matching my search expression. It should
not find the last two lines, as the number of characters between the # and $
are more than 10.

If I change the regular expression to "# [A-z]{1,10} $" then it finds the
first two lines but not the 3rd and 4th.

This seems like a software bug to me. Can anybody else confirm this?
 
H

Hagop

Your web site, while thorough, does not address this problem.

Graham Mayor said:
See http://www.gmayor.com/replace_using_wildcards.htm

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Wow. That gets everything in the extended ASCII set. Thanks so
much. I've put it into my tips file and will be modifying and
testing some of my search strings very soon. What I don't remember
are the differences in what ?, @, and * do. Can you tell me or
point me to a link?

PamC

Hi Hagop,

Try:
# [\!-ÿ]{1,10} $

My Microsoft Word 2003 document contains the following:

[quoted text clipped - 15 lines]

This seems like a software bug to me. Can anybody else confirm this?
 
H

Hagop

Didn't help.

macropod said:
OK,

Try:
# ??{1,8}? $

--
Cheers
macropod
[MVP - Microsoft Word]

PS: I agree that, intuitively, '# ?{1,10} $' should work.


Hagop said:
Okay. That (kind of) worked.

I failed to mention in my example that text I want to match may contain
spaces. This is only matching one word between the # and the $.

macropod said:
Hi Hagop,

Try:
# [\!-ÿ]{1,10} $

--
Cheers
macropod
[MVP - Microsoft Word]


My Microsoft Word 2003 document contains the following:

# aa $
# bb $
# AA!AA $
# BB.BB $
# aaaaaaaaaaaaaa $
# bbbbbbbbbbbbbb $

My search regular expression is "# ?{1,10} $"

Word is finding all these lines as matching my search expression. It should
not find the last two lines, as the number of characters between the # and $
are more than 10.

If I change the regular expression to "# [A-z]{1,10} $" then it finds the
first two lines but not the 3rd and 4th.

This seems like a software bug to me. Can anybody else confirm this?
 
G

Graham Mayor

Of course it does!

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Your web site, while thorough, does not address this problem.

Graham Mayor said:
See http://www.gmayor.com/replace_using_wildcards.htm

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Wow. That gets everything in the extended ASCII set. Thanks so
much. I've put it into my tips file and will be modifying and
testing some of my search strings very soon. What I don't remember
are the differences in what ?, @, and * do. Can you tell me or
point me to a link?

PamC


macropod wrote:
Hi Hagop,

Try:
# [\!-ÿ]{1,10} $

My Microsoft Word 2003 document contains the following:

[quoted text clipped - 15 lines]

This seems like a software bug to me. Can anybody else confirm
this?
 
H

Hagop

Please tell me where on your site you're saying that ?{n,m} returns erroneous
results. ?{1,10} should match 1 to 10 characters. It should match spaces,
punctuation, anything. It should not match 14 characters.

Graham Mayor said:
Of course it does!

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Your web site, while thorough, does not address this problem.

Graham Mayor said:
See http://www.gmayor.com/replace_using_wildcards.htm

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


PamC via OfficeKB.com wrote:
Wow. That gets everything in the extended ASCII set. Thanks so
much. I've put it into my tips file and will be modifying and
testing some of my search strings very soon. What I don't remember
are the differences in what ?, @, and * do. Can you tell me or
point me to a link?

PamC


macropod wrote:
Hi Hagop,

Try:
# [\!-ÿ]{1,10} $

My Microsoft Word 2003 document contains the following:

[quoted text clipped - 15 lines]

This seems like a software bug to me. Can anybody else confirm
this?
 
G

Graham Mayor

My reply to Pam's post addressed the issue that Pam raised "What I don't
remember are the differences in what ?, @, and * do. " which is what I
meant was covered on my web site.

As for your issue, you are right the search string gives erroneous results.
? and * especially should be used with care in a search string as they don't
always produce the expected results and personally I would never attempt to
use them with a range of characters #?{1,10}$ in fact works in the same way
as #*$ selecting all the characters between the # and $. You will also find
that #?{1,3}$ will do exactly the same - and you are right my web site could
do with a note to that effect. I'll add it when I have a minute or two.

# [A-z\!.]{1,10} $ will find the required results in your samples and my web
site explains how to expand the list to use the complete character set,
though Macropod's example should do the trick.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Please tell me where on your site you're saying that ?{n,m} returns
erroneous results. ?{1,10} should match 1 to 10 characters. It should
match spaces, punctuation, anything. It should not match 14
characters.

Graham Mayor said:
Of course it does!

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Your web site, while thorough, does not address this problem.

:

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

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


PamC via OfficeKB.com wrote:
Wow. That gets everything in the extended ASCII set. Thanks so
much. I've put it into my tips file and will be modifying and
testing some of my search strings very soon. What I don't
remember are the differences in what ?, @, and * do. Can you
tell me or point me to a link?

PamC


macropod wrote:
Hi Hagop,

Try:
# [\!-ÿ]{1,10} $

My Microsoft Word 2003 document contains the following:

[quoted text clipped - 15 lines]

This seems like a software bug to me. Can anybody else confirm
this?
 
M

macropod

Hi Hagop,

In what sense? It certainly worked in my testing with your data, with & without a space in the search string! If you want help,
you're going to have to do better than "Didn't help".

--
Cheers
macropod
[MVP - Microsoft Word]


Hagop said:
Didn't help.

macropod said:
OK,

Try:
# ??{1,8}? $

--
Cheers
macropod
[MVP - Microsoft Word]

PS: I agree that, intuitively, '# ?{1,10} $' should work.


Hagop said:
Okay. That (kind of) worked.

I failed to mention in my example that text I want to match may contain
spaces. This is only matching one word between the # and the $.

:

Hi Hagop,

Try:
# [\!-ÿ]{1,10} $

--
Cheers
macropod
[MVP - Microsoft Word]


My Microsoft Word 2003 document contains the following:

# aa $
# bb $
# AA!AA $
# BB.BB $
# aaaaaaaaaaaaaa $
# bbbbbbbbbbbbbb $

My search regular expression is "# ?{1,10} $"

Word is finding all these lines as matching my search expression. It should
not find the last two lines, as the number of characters between the # and $
are more than 10.

If I change the regular expression to "# [A-z]{1,10} $" then it finds the
first two lines but not the 3rd and 4th.

This seems like a software bug to me. Can anybody else confirm this?
 

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