Click to See Complete Forum and Search --> : regular expression Question


Ice3T
10-26-2003, 03:06 PM
Here is what I'm trying to do:
-asigne to an Array the value of each of the following lignes:

«
Chauffe-piscine
Foyer fournaise ( Max. 50 000 BTU / h )
Foyer-climatisant
Climatiseur-central
Surchauffeur eau chaude sanitaire (accessoires en option)
Chauffe résidentiel 1° génération ( Max. 60 000 BTU / h )
Chauffe-eau ( Max. 60 000 BTU / h )
Chauffe locatif 1° génération ( Max. 390 000 BTU / h )
Multi-locatif 2° génération ( Max. 390 000 BTU / h )
Chauffe-eau 3° génération ( Max. 390 000 BTU / h )
»

Note the amount of lignes and lenght are not known in advance. All I know is they all start with a capital ([A-Z]) and they all end with a carriage return (\r).

What I would love to is say:
from [A-Z] (included) to \r (excluded) asigne to Array and keep on going to the end of input.

Here is some of what I tryed:

string.match(/[A-Z]\S+\s(?!\r)/g);
the probleme here is I need to repeat the sequence «\S+\s(?!\r)» an unknown amount of times...

this does not seem to work either:
«/[A-Z](\S+\s(?!\r))+/g»

Charles
10-26-2003, 03:16 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<script type="text/javascript">
<!--
onload = function () {a = document.getElementById('data').value.split(/\n/); for (line in a) {alert (a[line])}}
// -->
</script>

<textarea id="data">Chauffe-piscine
Foyer fournaise ( Max. 50 000 BTU / h )
Foyer-climatisant
Climatiseur-central
Surchauffeur eau chaude sanitaire (accessoires en option)
Chauffe résidentiel 1° génération ( Max. 60 000 BTU / h )
Chauffe-eau ( Max. 60 000 BTU / h )
Chauffe locatif 1° génération ( Max. 390 000 BTU / h )
Multi-locatif 2° génération ( Max. 390 000 BTU / h )
Chauffe-eau 3° génération ( Max. 390 000 BTU / h )</textarea>

Ice3T
10-26-2003, 03:44 PM
... the word Jedi comes to mind.

Thank you Yoda... Euh, I mean Charles.

Ice3T
10-26-2003, 04:58 PM
Hi, I just noticed that the values of the a Array
« a = document.getElementById('data').value.split(/\n/); »
have a nasty space " " at the end of them. I would like to modify the code so that this does not happen,

thank you again,

Charles
10-26-2003, 05:02 PM
onload = function () {a = document.getElementById('data').value.split(/\s*\n/); alert (a)}

Ice3T
10-26-2003, 05:09 PM
Many thanks,