Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-05-2021, 10:47 AM
VBAFiddler VBAFiddler is offline Regular expression confusion! Windows 10 Regular expression confusion! Office 2016
Novice
Regular expression confusion!
 
Join Date: Feb 2021
Posts: 14
VBAFiddler is on a distinguished road
Post Regular expression confusion!

Hi,
My brain is about to overheat, as I've been trying to get a regular expression to do the following job.
I've been sent a document consisting of a biblical treatise. The author has asked me to mark all biblical references for indexing. They are in the following format where 9 equals numeric and X equals alphanumeric:
Xx. 99:99
9Xx. 99:99
Xx. 99:99-99
Using the find command, I can get the chapter and verse working, i.e.
[0-9]{1,2}:[0-9]{1,2}
But including the book, i.e.
[A-z][0-9]{1,3}. [0-9]{1,2}:[0-9]{1,2}


produces no results. To throw another spanner in the works, adding a -99 is optional, i.e. most don't but some do.
If anyone can come up with a way to include them all, I'd be extremely grateful. It may be that I end up having to find the chapter and vers, then extend the selection somehow,
Thanks,
Reply With Quote
  #2  
Old 02-05-2021, 01:58 PM
macropod's Avatar
macropod macropod is offline Regular expression confusion! Windows 10 Regular expression confusion! Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Instead of reinventing the wheel, see: https://www.msofficeforums.com/word-...ure-index.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-05-2021, 04:06 PM
VBAFiddler VBAFiddler is offline Regular expression confusion! Windows 10 Regular expression confusion! Office 2016
Novice
Regular expression confusion!
 
Join Date: Feb 2021
Posts: 14
VBAFiddler is on a distinguished road
Cool

Paul, Just the kind of answer I like. I'll read through this, and see how I get on,
Best,

David.
Reply With Quote
  #4  
Old 02-05-2021, 05:52 PM
VBAFiddler VBAFiddler is offline Regular expression confusion! Windows 10 Regular expression confusion! Office 2016
Novice
Regular expression confusion!
 
Join Date: Feb 2021
Posts: 14
VBAFiddler is on a distinguished road
Question Hmm, interesting but...

Quote:
Originally Posted by VBAFiddler View Post
Paul, Just the kind of answer I like. I'll read through this, and see how I get on,
Best,

David.
I'd still be interested to know a bit more about setting up a regular expression for my original criteria. Looking at your code, I can see a couple of or (|) in there, and I assume that it can be used to specify an alternative which isn't always true, but could be,
Thanks,

David.
Reply With Quote
  #5  
Old 02-05-2021, 08:33 PM
macropod's Avatar
macropod macropod is offline Regular expression confusion! Windows 10 Regular expression confusion! Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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 VBAFiddler View Post
I'd still be interested to know a bit more about setting up a regular expression for my original criteria.
For example:
Find = <[0-9A-Z]{1,2}[a-z.]{2,5} [0-9]{1,}:[!^s .,;”\)]{1,}
Note: the 5 in {2,5} assumes longer names are abbreviated.
Quote:
Originally Posted by VBAFiddler View Post
Looking at your code, I can see a couple of or (|) in there, and I assume that it can be used to specify an alternative which isn't always true, but could be
No. In StrBks, for example, they're used to delineate where | characters in the string are to be replaced by non-breaking spaces, which the board software doesn't support. This is explained in the preamble. In the calls to MakeDupes & HideDupes, they're used to delineate where | characters in the string are to be replaced by either a comma or semi-colon, depending on the user's regional settings.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 02-06-2021, 11:25 AM
VBAFiddler VBAFiddler is offline Regular expression confusion! Windows 10 Regular expression confusion! Office 2016
Novice
Regular expression confusion!
 
Join Date: Feb 2021
Posts: 14
VBAFiddler is on a distinguished road
Lightbulb Very many thanks

Aaargh! My dream of becoming a Word MVP moves ever further away. Impressed
Reply With Quote
  #7  
Old 02-09-2021, 03:27 PM
Charles Kenyon Charles Kenyon is offline Regular expression confusion! Windows 10 Regular expression confusion! Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by VBAFiddler View Post
Aaargh! My dream of becoming a Word MVP moves ever further away. Impressed

Be careful what you wish for!



Reply With Quote
  #8  
Old 02-12-2021, 04:30 AM
VBAFiddler VBAFiddler is offline Regular expression confusion! Windows 10 Regular expression confusion! Office 2016
Novice
Regular expression confusion!
 
Join Date: Feb 2021
Posts: 14
VBAFiddler is on a distinguished road
Question still an issue

Paul, Yes, this wheel you've invented is pretty good, but I'm using a slightly different vehicle. I don't normally mention this in the context of a forum, but I've no sight, and use a screen reader. Whilst I would like to get out of writing anything, the request from my friend is pretty specific. He wants all entries marked, then wants to create the index himself. The pattern you've recommended works fine, but I misled you (screen reader again). the books actually have a space between number and book, i.e. 1 Pe. Not to be defeated, I tried putting a \s into your pattern, but it found no results. on googling tutorials, I've found some rather patchy results. I am very happy to invent this particular wheel, and before reviving this thread, made every effort to find a solution.
Thanks,
David
Reply With Quote
  #9  
Old 02-12-2021, 01:30 PM
macropod's Avatar
macropod macropod is offline Regular expression confusion! Windows 10 Regular expression confusion! Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

In that case, as advised at the top of the post in the link, the spaces between the numbers and book names can be corrected:
Quote:
Originally Posted by macropod View Post
The code also requires books beginning with numerals (e.g. 1 Ki.) to have a non-breaking space between the numeral and the book's (abbreviated) name. If your document doesn't already use non-breaking spaces there, you can correct that before running the macros via a wildcard Find/Replace, where:
Find = (<[1-3]) ([CJKPST][a-z]@>)
Replace = \1^s\2
This also has the advantage of ensuring book references like '1 Ki.', '2|Tim.', etc., are kept together on the same line.
That should be sufficient to allow you to use the macros in the link. The only other thing you might need to change is some of the abbreviations the macro looks for; different authors follow a variety of abbreviation conventions. Hopefully your author is at least consistent in the way book names are abbreviated.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 02-12-2021, 03:21 PM
VBAFiddler VBAFiddler is offline Regular expression confusion! Windows 10 Regular expression confusion! Office 2016
Novice
Regular expression confusion!
 
Join Date: Feb 2021
Posts: 14
VBAFiddler is on a distinguished road
Default

Paul,
Many thanks. I'll certainly give it a spin now,
Best,
David.
Reply With Quote
  #11  
Old 02-12-2021, 03:31 PM
VBAFiddler VBAFiddler is offline Regular expression confusion! Windows 10 Regular expression confusion! Office 2016
Novice
Regular expression confusion!
 
Join Date: Feb 2021
Posts: 14
VBAFiddler is on a distinguished road
Default

Hi Paul,
Yes, getting into this now. Purely a question as to the mechanics of the regex.
1.What does the < sign signify at the beginning of a regex.
2.What does the | signify?
Thanks,
David.
Reply With Quote
  #12  
Old 02-13-2021, 01:16 AM
macropod's Avatar
macropod macropod is offline Regular expression confusion! Windows 10 Regular expression confusion! Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

The < and > characters specify that whatever follows or precedes, respectively, must represent the start or end of a string, rather than simply occurring somewhere within another string. Note that we're discussing Word wildcards here, not RegEx, per se. for more on Word wildcards, see: Finding and replacing characters using wildcards

I answered your question about | in post #5.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
bible reference, regular expression, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to use wild cards or regular expression in autocorrect kcvinu Word 2 12-14-2018 02:06 PM
Regular expression confusion! Regular Expression Syntax to Search for Alternative Words qubie Word 2 11-29-2017 05:48 AM
VBA code to enable Regular Expression ronmayerle Word VBA 2 11-20-2014 01:09 PM
Microsoft Expression Web ts6947 Misc 0 02-22-2013 08:20 AM
Regular expression confusion! Can pass .expression as a parameter? tinfanide PowerPoint 4 12-28-2012 06:14 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:29 PM.


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