Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Regular Expression Help

Regular Expression Help
Thread Tools
Dedicated MacNNer
Join Date: Feb 2001
Location: Manhattan
Status: Offline
Reply With Quote
Apr 5, 2002, 01:57 PM
 
doing a site and just realized that none of the text i've placed in bold tags is showing up as bold in netscape 4.7...soo, in our sitewide style guide i realize that we've had this problem before and made a bold class. i'm using homesite and want to do an extended search and replace to replace everything within the bold tags into font tags specifying the class (i like to use spans but we standardized on the font tag...but that doesn't matter...)

can anyone help me write a regular expression for use in homesite (or bbedit) that will take <b>*</b> and place it into <font class="Boldtext1">*</font>?

trying to just find everything in the bold tags, i used this:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier> /&lt;b&gt;[.]*&lt;\/b&gt;/ </font>[/code]
but it wasn't finding anything...

any help is much appreciated because i really can't afford to sort through ~200 html files for anything in bold tags...

thanks
     
Dedicated MacNNer
Join Date: Mar 2001
Location: Iowa City, IA
Status: Offline
Reply With Quote
Apr 5, 2002, 02:14 PM
 
Originally posted by ameat:
<STRONG>doing a site and just realized that none of the text i've placed in bold tags is showing up as bold in netscape 4.7...soo, in our sitewide style guide i realize that we've had this problem before and made a bold class. i'm using homesite and want to do an extended search and replace to replace everything within the bold tags into font tags specifying the class (i like to use spans but we standardized on the font tag...but that doesn't matter...)

can anyone help me write a regular expression for use in homesite (or bbedit) that will take &lt;b&gt;*&lt;/b&gt; and place it into &lt;font class="Boldtext1"&gt;*&lt;/font&gt;?

trying to just find everything in the bold tags, i used this:
&lt;BLOCKQUOTE&gt;&lt;font size="1"face="Geneva, Verdana, Arial"&gt;code:&lt;/font&gt;&lt;HR&gt;&lt;pre&gt;& amp;lt;font size=1 face=courier&gt; /&lt;b&gt;[.]*&lt;\/b&gt;/ &lt;/font&gt;&lt;/pre&gt;&lt;HR&gt;&lt;/blockquote&gt;
but it wasn't finding anything...

any help is much appreciated because i really can't afford to sort through ~200 html files for anything in bold tags...

thanks</STRONG>
Your problem is that you placed the . in a character class [], so the regexp is looking for 0 or more periods between bold tags. That's probably not what you meant.

However, this won't work either:

&lt;BLOCKQUOTE&gt;&lt;font size="1"face="Geneva, Verdana, Arial"&gt;code:&lt;/font&gt;&lt;HR&gt;&lt;pre&gt;& amp;lt;font size=1 face=courier&gt;
&lt;b&gt;.*&lt;\/b&gt;
&lt;/font&gt;&lt;/pre&gt;&lt;HR&gt;&lt;/blockquote&gt;

because regular expressions are greedy: They try to find the longest possible match. If, for example, you had the following line in your source:

I &lt;b&gt;hate&lt;/b&gt; using the &lt;FONT&gt; tag, but they &lt;b&gt;make&lt;/b&gt; me use it!

The above regexp would match this:

&lt;b&gt;hate&lt;/b&gt; using the &lt;FONT&gt;tag, but they &lt;b&gt;make&lt;/b&gt;

This is a difficult problem, in general, because you end up having to write an HTML parser. This might work:

&lt;BLOCKQUOTE&gt;&lt;font size="1"face="Geneva, Verdana, Arial"&gt;code:&lt;/font&gt;&lt;HR&gt;&lt;pre&gt;& amp;lt;font size=1 face=courier&gt;&lt;b&gt;[^&lt;]*&lt;/b&gt;&lt;/font&gt;&lt;/pre&gt;&lt;HR&gt;&lt;/blockquote&gt;

Read: Look for &lt;b&gt; followed by zero or more characters that are not &lt;, followed by &lt;/b&gt;.

This will fail when there is a tag within the &lt;b&gt; tag, e.g.:

&lt;b&gt;Click &lt;a href="url"&gt;this link&lt;/a&gt; now!&lt;/b&gt;

Also, all regexps will fail to match tags that open on one line and close on another unless there's an option to allow them to match across lines (default behavior is that they don't).

If your editor supports Perl-style extended regular expressions, you can write a more general solution. I can post one once I'm back home with my Perl book. But the above is about as close as vanilla regular expressions can get to solving your problem in one shot.

An alternative (which might be less of a head-ache) is a two-pass solution:

Search for &lt;b&gt; and replace with &lt;font class="Boldstyle1"&gt;, then search for &lt;/b&gt; and replace with &lt;/font&gt;.

Hope this helps.

[ 04-05-2002: Message edited by: Amorph ]
James

"I grew up. Then I got better." - Sea Wasp
     
ameat  (op)
Dedicated MacNNer
Join Date: Feb 2001
Location: Manhattan
Status: Offline
Reply With Quote
Apr 5, 2002, 02:48 PM
 
hey man, thanks a lot. i can almost guarantee that all of the bold tags are on one line and don't have other tags in front of them so your suggested method:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>&lt;b&gt;[^&lt;]*&lt;/b&gt;</font>[/code]

...would probably work. however i was impatient and did your final method...ie the two pass way earlier today. the regular expression thing was more of an experiment to see if i could do it for future use...

but again, thanks, it's something i've been meaning to learn...
     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
Apr 5, 2002, 04:13 PM
 
In BBEdit:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>search string: &lt;b&gt;([^&lt;]*)&lt;/b&gt;

replace string: &lt;font class=<font color = red>"BoldText1"</font>&gt;\<font color = blue>1</font>&lt;/font&gt;</font>[/code]
[Wevah setPostCount:[Wevah postCount] + 1];
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:52 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2