Simple (?) Regexp parsing question.

Jun 22, 2009 at 2:39am

Simple (?) Regexp parsing question.

Trying to get some weather data…specifically I am trying to get the data here:

I want the value of text, temp and date…searched the forums and found a text message example and tried to edit it to suit my needs, but I don’t really know what I am doing.

– Pasted Max Patch, click to expand. –
#44483
Jun 22, 2009 at 9:34am

Try these [regexp]s. If you want me to explain them character by character so you get a better understanding then just let me know.

lh

– Pasted Max Patch, click to expand. –
#159962
Jun 27, 2009 at 2:08am

Works well with the textbox, but not when I bang the line I want out of [text]….in [text] if there is the line:

it comes out as:

set

If its:

It comes out as:

Has no one written a proper string external that gets around all of max’s formatting?

the quotes/formatting gets all messed up…any way to fix that?

#159963
Jun 27, 2009 at 4:50am

Ok so I’m trying to hack together a .js that will scan lines and replace ” with “

This code was working a bit ago, but now all of a sudden It wont compile

i send it the message

[readlines "path/data.txt"]

where path is the current filepath to my file…

// inlets and outlets
inlets = 2;
outlets = 2;
setinletassist(0,”inlet1″);
setoutletassist(0,”output0″);

function readlines(s)
{
var f = new File(s);
var i, a, a0;

if (f.isopen) {

i=0;
while (i<15){
a0=f.readline();

if (f.readline()){
a = a0.replace(“”", “”", “gi”);
outlet(0, a);
}
i++;
}
f.close();
} else {
post(“could not open file: ” + s + “n”);
}
}

What gives? The problem seems to be: a0.replace(“”", “”", “gi”);

looks like “”" gives the error..

#159964
Jun 27, 2009 at 8:39am

That’s because you need to escape characters even in javascript. “” Is an empty string so “”" is an empty string followed by an illegal “quote”. Try the line below which should work for you:

outlet(0, line.replace(""", "\"", "gi"));

The “”" is an escaped quote mark as a string, the second is an escaped slash followed by an escaped quote mark as a string. It looks a bit odd but it fixes your problem. You could even do all the regexp parsing inside the javascript.

lh

#159965

You must be logged in to reply to this topic.