PDA

View Full Version : How to find string with 2 digits only?



wdorciak
10-28-2010, 11:21 AM
I have some strings in format AA-999 and AA-99.

How can I find AA-99 only that is not the part of AA-999?

Searching for AA-[0-9][0-9]{2,2} seems to only find AA-999.

Thanks, Walter.

macropod
10-28-2010, 02:47 PM
Hi Walter,

Try Find = AA-[0-9]{2}>

Your find string tells Word to find 'AA-', followed by 0-9, then followed by a further two instances of 0-9 - in effect, 'AA-', followed by three digits. The '>' in my find string tells Word that the pair of digits must terminate a 'word', thus avoiding potential matches with three digits.

wdorciak
10-28-2010, 03:25 PM
Thanks, that seems to work well :pleased: .

Curious, what terminates a word? Anything other then A-Z and 0-9?

Because we have some that are in parenthesis, like (AA-99), and it finds those as well.

Regards, Walter.

wdorciak
10-28-2010, 03:29 PM
Also, do I want to use AA-[0-9]{2}> or AA-[0-9]{2,2}>?

Thanks, W.

wdorciak
10-28-2010, 03:57 PM
Actually, doing some more testing, this syntax works as well.

AA-[0-9]{2,3}

macropod
10-28-2010, 04:03 PM
Hi Walter,

In general terms, 'words' are terminated by spaces & punctuation marks.

In your original post, you said:
How can I find AA-99 only that is not the part of AA-999?
Changing the find code to AA-[0-9]{2,3} means you won't achieve that aim, since you'll find 'AA-' followed by two or more digits (the '3' suggests 3 digits but, without the '>', there is no specification about the 'word' ending - you may as well use AA-[0-9]{2}).

wdorciak
10-28-2010, 04:05 PM
Thanks, will have to thing about it some more.