Regular Expression help - PHP
Author
Discussion

size13

Original Poster:

2,033 posts

287 months

Thursday 23rd June 2005
quotequote all
I can't seem to find anything like this in any documentation.

I have some data, like

020 $a0750939486 (hbk.) :$c£19.99 : CIP entry (Feb.)

I'm using preg_split in PHP to split that data at each of the $ symbols. The problem is, if $ currency is used in the data they use $$. How do I use a regular expression to say that I only want it to split when there is a single $, rather than two?

e.g. the above example might instead be

020 $a0750939486 (hbk.) :$c$$19.99 : CIP entry (Feb.)

zaktoo

1,401 posts

270 months

Thursday 23rd June 2005
quotequote all
I'm not sure if the php regex implementation has negative look-aheads, but if it does, it would be something like

$(?!$)

HTH

Ciao

Zak

size13

Original Poster:

2,033 posts

287 months

Thursday 23rd June 2005
quotequote all
I seem to have ended up with this...

preg_split("/[$(?!$)]/", $data);

Does that make sense?

(I no nothing about regular expressions)

zaktoo

1,401 posts

270 months

Thursday 23rd June 2005
quotequote all
Not sure why you're putting the [ and ] in there...

/$(!?$)/ should suffice. I know little about php though... :/

Ciao

Zak

>> Edited by zaktoo on Thursday 23 June 16:14

size13

Original Poster:

2,033 posts

287 months

Thursday 23rd June 2005
quotequote all
zaktoo said:
Not sure why you're putting the [ and ] in there...

/$(!?$)/ should suffice. I know little about php though... :/

Ciao

Zak

>> Edited by zaktoo on Thursday 23 June 16:14

without the [] I don't get any split, with it, I do.

I'll test a little further

zaktoo

1,401 posts

270 months

Thursday 23rd June 2005
quotequote all
just by the way - PH is stripping out the backslash ccharacters in my posts - not sure if you've got 'em in too - but there's one backslash before each $. Perhaps that makes a difference?

Ciao

Zak