PDA

View Full Version : [SOLVED:] Regular expressions to locate roman numerals and specific words



ma_roberge
09-30-2016, 12:40 PM
I need to be able to insert unbreakable spaces between (1) a name and a roman numeral and (2) the word "op." (opus) and a number. I have the following find and replace strings with wildcards checked:

Find: ([A-Za-z])( )([CDILMVX]){1;}, Replace: \1^s\3
Find: ([op.])([ ])([0-9]), Replace: \1^s\3

My problem is that more than I need gets an unbreakable space, because Word/VBA does not understand that it should not pick any letter in the find strings and consider them valid matches.

"Louis XIV" needs a space, but "tell Vincent" does not; and "op. 12" needs one, but "pop 12" does not.

Is there a way to achieve what I want, or is Word's implementation of regular expressions not complete enough? Thanks in advance.

gmaxey
10-01-2016, 05:29 AM
Perhaps:

(<[A-Z][a-z]{1,})( )([CDILMVX.]{1,}>)
(op.)( )([0-9]{1,})

ma_roberge
10-02-2016, 07:58 AM
Greg,

Thanks for your help. As far as my current tests show, the corrected code works (though I deleted the period at the end of the string of roman numerals). The only problem is that I appear to need two calls in the second case: one for "op.", another for "Op." Using "[Oop.]" will add an unbreakable space to "pop 12". As far as I know, it is not possible with Word to have something like "op.|Op." (operator OR).

gmaxey
10-02-2016, 04:04 PM
Try:

([Oo]p.)( )([0-9]{1,})

ma_roberge
10-02-2016, 04:19 PM
I thought I had tried this possibility, but surely not enough! You have the solution; thanks.