Page 1 of 1

How can I use regex to add css to chapter & verse numbers?

Posted: Wed Apr 08, 2009 10:36 pm
by Indianbear
Hello,

I'm using Dreamweaver CS4. I'm fairly new at it. I'm comfortable using find and replace but I have never had to use Regex before.

I'm working on a copy of the New Testament. I want to use a CSS style to change the appearance of the chapter and verse numbers.

As you know there is a chapter number, then a colon, then a verse number. There are four combinations of numbers. Examples are: 1:1, 1:10, 10:1 and 10:10

What I want to do is wrap this CSS style "<span class="VerseNumbers"> </span>" around each set of numbers. The numbers need to be left unchanged, I just want to add the CSS.

Example:<span class="VerseNumbers">10:10</span>

Here is a copy of the source code before any changes.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

from the east to Jerusalem.<br />
2:2 Saying, Where is he that is born king of the Jews? For we have seen his star in the east and have come to adore him.<br />
2:34 King Herod hearing this, was troubled and all Jerusalem with him.<br />
12:4 Assembling together all the chief priests and the scribes of the people, he inquired of them where Christ should be born.<br />
12:56 But they said to him, In Bethlehem of Judea. For so it is written by the prophet,<br />

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Here is what it should look like after adding the CSS.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

from the east to Jerusalem.<br />
<span class="VerseNumbers">2:2</span> Saying, Where is he that is born king of the Jews? For we have seen his star in the east and have come to adore him.<br />
<span class="VerseNumbers">2:34</span> King Herod hearing this, was troubled and all Jerusalem with him.<br />
<span class="VerseNumbers">12:4</span> Assembling together all the chief priests and the scribes of the people, he inquired of them where Christ should be born.<br />
<span class="VerseNumbers">12:56</span> But they said to him, In Bethlehem of Judea. For so it is written by the prophet,<br />

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

I've done some reading about regular expressions, but I have had no success in figuring out how to make it work for my particular need. I keep wiping out the numbers. I sure hope it can be done. I'm looking at a LOT of numbers to change.

Any advice would be greatly appreciated.

Thanks.

Re: How can I use regex to add css to chapter & verse numbers?

Posted: Thu Apr 09, 2009 2:28 am
by prometheuzz
I don't know if Dreamweaver's regex engine supports "group matching" and "interpolating" these groups into a replacement string. If it does, you can doe this:

Code: Select all

regex       : (\d{1,2}:\d{1,2})
replacement : <span class="VerseNumbers">$1</span>
An explanation:

Code: Select all

(           // start match group 1
  \d{1,2}   // a number once or twice
  :         // a colon
  \d{1,2}   // a number once or twice
)           // end match group 1

And the $1 (called variable interpolation) in the replacement string will hold what is matched by group 1 in your regex pattern.

If Dreamweaver does not support these things, you will have to use another tool to do these replacements.

HTH

Re: How can I use regex to add css to chapter & verse numbers?

Posted: Thu Apr 09, 2009 5:42 am
by Indianbear
prometheuzz,

Your code works like a charm, and in Dreamweaver.

Thank you VERY much for your help. You saved me a lot of work. :D

Frank

Re: How can I use regex to add css to chapter & verse numbers?

Posted: Thu Apr 09, 2009 6:29 am
by prometheuzz
Indianbear wrote:prometheuzz,

Your code works like a charm, and in Dreamweaver.

Thank you VERY much for your help. You saved me a lot of work. :D

Frank
You're welcome.

Regards,

Bart.