yerk5@hotmail.com wrote:[color=blue]
> Wow much appreciated. To get specific, the strings I want to extract
> will not actually be prefixed with any delimiting word or phrase, so[/color]
I[color=blue]
> think maybe trying to string match wont work.
>
> Here's a sample of what I'd really be using. I'd want to paste (and
> it's going to look horrible if youre not viewing this with a fixed
> width font):
>
> |---------||-|---|--|----------------|--|-|-|-|----|
> |City |St|Exc|SC|Eta 21:11 hrs |Cn|C|P|D|Rte |
> :---------:--:---:--:----------------:--:-:-:-:----:
> |CHINO |CA|ONT| |03/10/2005 17:21|Y |N|C|N|0000|
> |INDEPENDE|OR|RNO| |03/11/2005 15:32| |C|N|N|0960|
> | | | | | | | | | | |
>
> So the dates and time are what I want to extract out into a var. The
> only thing constant about them will be their position, so I'm[/color]
thinking[color=blue]
> that woudl be the best approach to capturing them, but I'm lost as to
> how. :([/color]
See if this is anywhere in the vicinity...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/str**ict.dtd">
<html>
<head>
<title>untitled</title>
<style type="text/css">
#extractor {
width: 440px;
height: 100px;
}
input {
width: 80px;
}
</style>
<script type="text/javascript">
function extract(obj)
{
var citypos, etapos,
oData = {}, str, spc, city, date, time,
line, lines = obj.value.split('\n');
for (var l = 0, ls = lines.length; l < ls; ++l)
{
line = lines[l];
citypos = etapos = -1;
citypos = line.search(/\bcity\b/i);
etapos = line.search(/\beta\b/i);
if (citypos > -1 && etapos > -1)
break;
}
for (++l; l < ls; ++l)
{
line = lines[l];
str = line.substring(citypos);
if (city = str.match(/[a-z]+/i))
{
str = line.substring(etapos);
if (spc = str.indexOf(' '))
date = str.substring(0, spc);
time = str.substring(spc + 1);
if (/\d{1,2}\/\d{1,2}\/\d{2,4}/.test(date)
&& (time = time.match(/\d{1,2}:\d{1,2}/)))
{
oData[city] = { date: date, time: time };
}
}
}
return oData;
}
function showData(obj)
{
var data = extract(obj);
var str = '';
for (city in data)
str += 'city: ' + city +
'\ndate: ' + data[city]['date'] +
'\ntime: ' + data[city]['time'] + '\n\n';
alert(str);
}
</script>
</head>
<body>
<form>
<textarea
id="extractor"
name="extractor">|---------||-|---|--|---------*-------|--|-|-|-|----|
|City |St|Exc|SC|Eta 21:11 hrs |Cn|C|P|D|Rte |
:---------:--:---:--:---------*-------:--:-:-:-:----:
|CHINO |CA|ONT| |03/10/2005 17:21|Y |N|C|N|0000|
|INDEPENDE|OR|RNO| |03/11/2005 15:32| |C|N|N|0960|
| | | | | | | | | | |</textarea>
<input type="button"
value="test"
onclick="showData(extractor)" />
</form>
</body>
</html>
(assuming googlegroups doesn't mangle it beyond repair). Not sure what
you wanted, exactly. This returns an object (oData) whose properties
(named for the city in question) contain another object with 'date' &
'time' properties, self-explanatory. Easily rearranged mini-dB. Overdid
the parsing a bit but it's not entirely clear how reliably formatted
the pasted string will be.
Of course, if Mick W. nailed it,
just
ignore
this &
have a nice day.
#:=D