Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-15-2015, 08:35 PM
tinfanide tinfanide is offline Word Regular Expressions: zero or more occurences? Windows 7 64bit Word Regular Expressions: zero or more occurences? Office 2010 32bit
Expert
Word Regular Expressions: zero or more occurences?
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default Word Regular Expressions: zero or more occurences?

C
C1


C2
CA

Code:
[A-Z]{1}[0-9]{0,1}
[A-Z]{1}[0-9]*
[A-Z]{1}[0-9]?
The above three still cannot find "C", but only "C1" and "C2".
Is there anything wrong with the use of * and ?
It seems that {0,1} is a wrong use.
Reply With Quote
  #2  
Old 09-15-2015, 08:59 PM
macropod's Avatar
macropod macropod is offline Word Regular Expressions: zero or more occurences? Windows 7 64bit Word Regular Expressions: zero or more occurences? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

If you consider what '0 or more occurrences' means, in the context of looking for [A-Z]{1} followed by '0 or more occurrences' of [0-9], that's really no different than looking for [A-Z]*; after all, '0 or more occurrences' means you don't really care whether there are any of [0-9] after [A-Z].
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 09-15-2015, 09:06 PM
tinfanide tinfanide is offline Word Regular Expressions: zero or more occurences? Windows 7 64bit Word Regular Expressions: zero or more occurences? Office 2010 32bit
Expert
Word Regular Expressions: zero or more occurences?
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Maybe I should have put it more clearly.

I want to find

C
C1
C2

but not

CA

If Find What: [A-Z]*
it returns C, C1, C2 and CA (which is not wanted).
Reply With Quote
  #4  
Old 09-15-2015, 09:35 PM
macropod's Avatar
macropod macropod is offline Word Regular Expressions: zero or more occurences? Windows 7 64bit Word Regular Expressions: zero or more occurences? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
<[A-Z][!A-Za-z.,\!:;^13]{1,}
Note that the 'C' match per your example will include the following space, if there is one, but it won't match 'C' followed by any of !:;^13.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 09-16-2015, 06:09 AM
tinfanide tinfanide is offline Word Regular Expressions: zero or more occurences? Windows 7 64bit Word Regular Expressions: zero or more occurences? Office 2010 32bit
Expert
Word Regular Expressions: zero or more occurences?
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Quote:
The construction {0,} (find zero or more of the preceding item) is refused as incorrect syntax. This concept is available in Unix regular expression matching, so it's a curious omission.
From:
http://word.mvps.org/faqs/general/usingwildcards.htm

It states that zero or more occurences is rejected by Word as incorrect syntax and thus not available in Word Find & Replace.

And,

Your codes cannot find "C".
Reply With Quote
  #6  
Old 09-16-2015, 08:08 AM
macropod's Avatar
macropod macropod is offline Word Regular Expressions: zero or more occurences? Windows 7 64bit Word Regular Expressions: zero or more occurences? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by tinfanide View Post
Your codes cannot find "C".
I did say it would find 'C ' (it will also find 'C.' and 'C,'), but not 'C!', 'C:' 'C;' or 'C^13'. A document cannot have 'C' (i.e. C with nothing after it)...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 09-16-2015, 03:13 PM
tinfanide tinfanide is offline Word Regular Expressions: zero or more occurences? Windows 7 64bit Word Regular Expressions: zero or more occurences? Office 2010 32bit
Expert
Word Regular Expressions: zero or more occurences?
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Yes, I got it. Thanks.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Regular Expressions: zero or more occurences? regular expressions in footnotes loes Word 3 09-04-2019 07:52 AM
Word Regular Expressions: zero or more occurences? Regular expressions for text with complex formatting Kreol2013 Word VBA 1 04-12-2013 07:33 PM
regular expressions for empty lines eNGiNe Word 1 01-21-2013 06:38 AM
Word Regular Expressions: zero or more occurences? Regular Expressions: [!0-9] does not work??? tinfanide Excel Programming 4 05-30-2012 04:09 AM
Issue skipping characters by Regular Expressions in Word pochtara Word VBA 0 04-01-2010 05:37 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:21 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft