Results 1 to 5 of 5
Thread: IE + regex + split() != fun
Jul 6, 2007, 04:46 #1
- Join Date
- Jul 2007
- 0 Post(s)
- 0 Thread(s)
IE + regex + split() != fun
I'm putting together something for a property selling web site to list the particulars of each property. I've loaded all the properties from the DB (*cough* large text file) into a huge 2D array and one column is a freeform(ish) field called "Remarks" that will contain the blurb.
I've managed to convince the people that write the details to stick to a fairly rigid format to make it easier to parse out to the screen. So the general format of the field is:
HEADING: description. HEADING: description leading to... HEADING: description. and so on
where HEADING is all in capitals, immediately followed by a colon, and may contain spaces, hyphens, slashes or numbers. The 'description' can be pretty much any characters, or may be empty if there's a double heading such as FIRST FLOOR: BEDROOM 1:
So I want to split this mammoth text field into its component "HEADING" and "description" parts such that I can iterate over them and apply formatting by shoving each bit into divs or table cells to separate them.
The issue is slightly murkier because the HEADING is normally a room of the house and thus could be simple like "BEDROOM 3" or could be "W.C." or perhaps "SPARE/UTILITY ROOM". They also sometimes start a paragraph in the description field with "N.B:", which is infuriating but I guess I'll just have to treat it as a HEADING.
The problem is JScript/IE (6, not sure about 7) and its handling of split and regexes. Firefox works a charm with this [horrible] expression:
regex = /(W\.C|N\.B|[A-Z1-9\s*\/-]+:)+(.*?)/g; remarkItems = properties[currPropIdx].remarks.split(regex);
Can anyone with a bigger brain then me perhaps suggest a way of making this work more cross-browser, or point me in a new direction; perhaps using some other means of splitting this string up? It's probably monumentally easy and I'm just being stupid, but staring at the code, making adjustments and proclaiming "why!?" a lot hasn't got me very far
Thanks in advance for any pointers.
btw, here's some sample output of the field in question:
THE ACCOMMODATION PROVIDES: Door to… ENTRANCE HALL: Carpet, stairs to first floor, radiator panel, door to… W.C: Low level w.c. LOUNGE: Approx 4.26m x 4.23m (14` x 13`9`). Carpet, gas fire as fitted, power points, radiator panel. KITCHEN: Approx 3.01m x 2.74m (9`9` x 9`). Wall and floor cupboards as fitted, stainless steel sink unit, `potterton` gas boiler for hot water and central heating, space for appliance, larder cupboard, power points. DINING ROOM: Carpet, radiator panel, power points, coved and artex ceiling. FIRST FLOOR: LANDING: Carpet, airing cupboard containing hot water cylinder, hatch to loft, door to… BEDROOM 1: Approx 4.26m into bay reducing to 3.74m in to bay x 3.44m (14` into bay reducing 12`3` into bay x 11`3`). Carpet, radiator panel, coved ceiling, recess cupboard, power points. BEDROOM 2: Approx 3.74m x 3.04m (12`3` x 10`). Carpet, radiator panel, recess cupboard, power points. BEDROOM 3: Approx 2.74m x 2.74m (9` x 9`). Carpet, radiator panel, fitted cupboards, power points. BATHROOM: Enamel bath and shower attachment, vanity wash hand basin, low level w.c, radiator panel, carpet. OUTSIDE: Lawn to front with off street parking for 2 cars, rear garden with lawn, brick sheds, shrubs, green house, fence borders. COUNCIL TAX: Band `C` VIEWING: By appointment with the Agents.