RegEx replacement problem -- SOLVED

General questions about using WildEdit

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Mikebert4
Posts: 6
Joined: Thu Apr 03, 2008 10:49 am

RegEx replacement problem -- SOLVED

Post by Mikebert4 »

Hi there,

I've been wrapping my head round this for some time:

I have a set of 361 HTML files, which each contain two mapped .gif images (for hotspots).

I need to replace instances of

Code: Select all

  <area href="../SMDdata/XXX.htm" alt="XXX" title="XXX" shape="rect" coords="x,x,x,x">
where 'XXX' is a string of varying length (including spaces) and 'x' is a 3-digit number

with:

Code: Select all

  <area href="../ATPdata/XXX.htm" alt="XXX" title="XXX" shape="rect" coords="x,x,x,x">
However, There are instances of these tags in the files where I don't want to make this replacement. I only want to change them in the first image map.

The first image map loos like this:

Code: Select all

<map id="imgMap" name="imgMap">
 --<Area> tags here ---
</map>
and the second:

Code: Select all

 
<map id="othimgMap" name="othimgMap">
 --<Area> tags here ---
</map>


Can anyone help me?

Thanks in advance!
Mike
Last edited by Mikebert4 on Thu Apr 03, 2008 3:55 pm, edited 1 time in total.
When a clock is hungry, it goes back four seconds.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Does this do it?
Find what: <area href="../SMDdata/([^"]+).htm" (?=.*<map id="othimgMap")
Replace with: <area href="../ATPdata/$1.htm" $2

[X] Regular expression
[X] Replacement format

Options
[ ] '.' does not match a newline character [i.e., not selected]
I've made some assumptions in order to shorten the regex. It may need to be adjusted if my assumptions are invalid.
Mikebert4
Posts: 6
Joined: Thu Apr 03, 2008 10:49 am

Post by Mikebert4 »

Thanks for the quick reply!

Unfortunately - that makes no replacements.

is there a setting I'm missing?

Currently my options looks like:

[]Use POSIX extended...
[]Use locale specific collation..
[]Newline separates alternatives
[]'|' is literal unless escaped
[]'+' and '?' is literal unless escaped
[]'(' and ')' is literal unless escaped
[]'{' and '}' is literal unless escaped
[]'\' is literal unless escaped

[]'.' does not match a newline character
[]'.' does not match a null character

...
also - here's a sample file for you to oggle:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" >
<meta http-equiv="Page-Enter" content="blendTrans(Duration=0.5)">
<meta http-equiv="Page-Exit" content="blendTrans(Duration=0.5)">
<meta http-equiv="Site-Enter" content="blendTrans(Duration=0.5)">
<meta http-equiv="Site-Exit" content="blendTrans(Duration=0.5)">
    <title>
CA 3
    </title>

  <script language="javascript1.2" type="text/javascript" src="../../main.js">
<!--
//-->
</script>
<link href="../../SMD_files/main.css" rel="stylesheet" type="text/css"></link>
</head>
  <body>

    <div id="content-wrapper">

<!-- header elements -->
<div id="header"><!-- --></div>
	<div id="content">
<div class="spacer"><!-- --></div>

<!-- ATP points -->

<div id="ATP" style="display: none">

<a class="switchlink" onClick="ptswitch(SMD)"> Show SMD points </a>
<div class="spacer"><!-- --></div>
<!-- ATP image -->
      <img src="ATPmap.gif" usemap="#imgMap" border="0" width="768" height="1056.htm" alt="map">
      <map id="imgMap" name="imgMap">
  <area href="../ATPdata/FREEL001.htm" alt="FREEL001" title="FREEL001" shape="rect" coords="377,228,393,244">
<area href="../Terridata/CA 3.htm" alt="CA 3" title="CA 3" shape="poly" coords=" >>Too many to list here<< "
   <area href="javascript: history.go(-1)" alt="Back" title="Back" shape="rect" coords="0,0,768,1056">
</div>

<!-- SMD points -->

<div id="SMD" style="display: block">

<a class="switchlink" onClick="ptswitch(ATP)"> Show ATP points </a>
<div class="spacer"><!-- --></div>
<!-- SMD image -->
      <img src="SMDmap.gif" usemap="#othimgMap" border="0" width="768" height="1056.htm" alt="map">
      <map id="othimgMap" name="othimgMap">
   <area href="../SMDdata/BAKER001.htm" alt="BAKER001" title="BAKER001" shape="rect" coords="508,601,527,619">
   <area href="../SMDdata/FREEL009.htm" alt="FREEL009" title="FREEL009" shape="rect" coords="376,227,395,246">
   <area href="../SMDdata/HERBE001.htm" alt="HERBE001" title="HERBE001" shape="rect" coords="447,128,466,147">
<area href="../Terridata/CA 3.htm" alt="CA 3" title="CA 3" shape="poly" coords=" >>Too many to list here<< "
   <area href="javascript: history.go(-1)" alt="Back" title="Back" shape="rect" coords="0,0,768,1056">
    </map>
          </div>
          </div>

<!-- footer elements -->
<div id="footer">
	<div id="upfooter"><!-- --></div>
	<div id="botfooter"><!-- --></div>
</div>
</div>
  </body>
</html>
The files differ only ion the following:
  • The images,
  • The number and position of the clickable points,
  • The files the clickable points point to,
  • The <area shape="poly"> coordinates also change between files
[/list]
When a clock is hungry, it goes back four seconds.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

That's because there aren't any <area href="../SMDdata/ ...> elements within the <map id="imgMap" name="imgMap"> element.
Mikebert4
Posts: 6
Joined: Thu Apr 03, 2008 10:49 am

Post by Mikebert4 »

Haha, trust me to choose one of the few files that didn't have any points in them! :)

this one's a little more typical:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" >
<meta http-equiv="Page-Enter" content="blendTrans(Duration=0.5)">
<meta http-equiv="Page-Exit" content="blendTrans(Duration=0.5)">
<meta http-equiv="Site-Enter" content="blendTrans(Duration=0.5)">
<meta http-equiv="Site-Exit" content="blendTrans(Duration=0.5)">
    <title>
CA 32
    </title>

  <script language="javascript1.2" type="text/javascript" src="../../main.js">
<!--
//-->
</script>
<link href="../../SMD_files/main.css" rel="stylesheet" type="text/css"></link>
</head>
  <body>

    <div id="content-wrapper">
<div id="header"><!-- --></div>
	<div id="content">
<div class="spacer"><!-- --></div>

<div id="ATP" style="display: none">

<a class="switchlink" onClick="ptswitch(SMD)"> Show SMD points </a>
<div class="spacer"><!-- --></div>
      <img src="ATPmap.gif" usemap="#imgMap" border="0" width="768" height="1056.htm" alt="map">
      <map id="imgMap" name="imgMap">
  <area href="../ATPdata/WINDO001.htm" alt="WINDO001" title="WINDO001" shape="rect" coords="497,440,512,456">
  <area href="../SMDdata/ALEXA001.htm" alt="ALEXA001" title="ALEXA001" shape="rect" coords="496,475,511,491">
  <area href="../SMDdata/DEWIN001.htm" alt="DEWIN001" title="DEWIN001" shape="rect" coords="132,582,148,597">
  <area href="../Terridata/CA 32.htm" alt="CA 32" title="CA 32" shape="poly" coords="many, many, coords">
  <area href="javascript: history.go(-1)" alt="Back" title="Back" shape="rect" coords="0,0,768,1056">
</div>
<div id="SMD" style="display: block">

<a class="switchlink" onClick="ptswitch(ATP)"> Show ATP points </a>
<div class="spacer"><!-- --></div>
      <img src="SMDmap.gif" usemap="#othimgMap" border="0" width="768" height="1056.htm" alt="map">
      <map id="othimgMap" name="othimgMap">
   <area href="../SMDdata/CARGO001.htm" alt="CARGO001" title="CARGO001" shape="rect" coords="609,535,627,554">
   <area href="../SMDdata/ALEXA001.htm" alt="ALEXA001" title="ALEXA001" shape="rect" coords="494,474,513,492">
   <area href="../Terridata/CA 32.htm" alt="CA 32" title="CA 32" shape="poly" coords="many, many, coords">   <area href="javascript: history.go(-1)" alt="Back" title="Back" shape="rect" coords="0,0,768,1056">
    </map>
          </div>
          </div>

<div id="footer">
	<div id="upfooter"><!-- --></div>
	<div id="botfooter"><!-- --></div>
</div>
</div>
  </body>
</html>

>> EDIT: on going through the files, it looks like your syntax changed the first instance of .../SMDdata/... in those that had it... I'm going to see if running it repeatedly effects the solution I'm after <<

>>>EXTRA EDIT: it doesn't work like that aparently :'( <<<

Thanks for helping me on this :)
When a clock is hungry, it goes back four seconds.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Mikebert4 wrote:it doesn't work like that aparently
Can you be a little more specific? It works here; it made two replacements in the example you just supplied.

If you copied the regular expression from this web page, make sure a spurious space didn't get stuck on the end.
Mikebert4
Posts: 6
Joined: Thu Apr 03, 2008 10:49 am

Post by Mikebert4 »

Sorry -

What actually happened is this:

I managed to replace the first instance of ../SMDdata in the files by running the following straight replace:
Replace:

Code: Select all

<map id="imgMap" name="imgMap">
  <area href="../SMDdata/
With:

Code: Select all

<map id="imgMap" name="imgMap">
  <area href="../ATPdata/
All my ranting about it 'only replacing the first' is because I'm an idiot and forgot that I'd done this.

If the regular expression you supplied is working fine at your end, is there a setting I'm missing and ought to have checked/unchecked in order to get it working?

Also - I don't know if this has any baring on the outcome, but these files are nested two folders down in a folder structure, thus:

Code: Select all

Territories-
      |
      ----Territory1----index.htm <--the file
      |            |
      |            --------gif1
      |            |
      |            --------gif2
      |
      ----Territory2----index.htm <--the file
      |            |
      |            --------gif1
      |            |
      |            --------gif2
      |
      ----Territory3----


etc...
(obvoiusly I have "[*] Search subfolders")
When a clock is hungry, it goes back four seconds.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

I don't understand. Are you asking about my suggestion, which works, or yours, which doesn't?
Mikebert4
Posts: 6
Joined: Thu Apr 03, 2008 10:49 am

Post by Mikebert4 »

Your suggestion:
ben_jospehs wrote:
Find what: <area href="../SMDdata/([^"]+).htm" (?=.*<map id="othimgMap")
Replace with: <area href="../ATPdata/$1.htm" $2

[X] Regular expression
[X] Replacement format

Options
[ ] '.' does not match a newline character [i.e., not selected]
Doesn't work at my end.

I was asking if there's a setting I may have missed?
When a clock is hungry, it goes back four seconds.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

I have no idea why it's not working for you, because you still haven't given any details about how it fails. "Doesn't work" is not very helpful. Can you at least post WildEdit's log?
Mikebert4
Posts: 6
Joined: Thu Apr 03, 2008 10:49 am

Post by Mikebert4 »

Well, there's no need to post the log at least -

I've just tried it again and it worked - I think I copied a space on the end of your expression the first few times


Anyway, it worked a treat!

Thanks so much for helping, and for letting me get you utterly confused. At some point I'll set aside some serious time to learn Regular Expressions and their little ways.



P.S - I assume this'll work for any situation of "Replace all instances of 'x' before 'y'"?

for example:
Replace:
{bit that wants replacing}([^"]+){something else that occurs on all instance where you want a replacement} (?=.*{bit that it should stop at})
With:
{replacement string}$1{the other bit (can replace in here too)} $2
When a clock is hungry, it goes back four seconds.
Post Reply