Page 1 of 1

could not find where is it going wrong

Posted: Wed Jan 31, 2007 10:05 am
by raghavan20
i have blocks like this in a file which have to be extracted.

Code: Select all

LIN+1+3+9780194346092:EN++2'
QTY+52:100'
DTM+44:19971009:102'
FTX+LIN++IP:8B:28'
TAX+7+VAT+++:::17.5+S'
MOA+125:21.6'
PRI+AAE:25.38::SRP'
ALC+A+EQ'


LIN+2+3+9780192717931:EN++2'
QTY+52:0'
DTM+44:19980521:102'
FTX+LIN++OP:8B:28'
TAX+7+VAT++++Z'
PRI+AAE:12.99::SRP'
ALC+A+CK'
i want to take in blocks of ( LIN .... ALC..' )


my code is

Code: Select all

$regex = '#\bLIN.*?ALC.*?\'#mi';
	preg_match_all( $regex, $fileContents, $blocks );
	print_r( $blocks );
can anyone see what is wrong in there?

Posted: Wed Jan 31, 2007 11:11 am
by feyd
"m" (multiline) mode makes it look for a single line.

Posted: Fri Feb 02, 2007 11:12 pm
by Ciprian
here is something that should work:

$regex = '#^LIN.*|ALC.*\'#im';

Have fun.

Posted: Sat Feb 03, 2007 5:52 am
by raghavan20
Ciprian wrote:here is something that should work:

$regex = '#^LIN.*|ALC.*\'#im';

Have fun.
i do not want LIN or ALC lines but i want from LIN to ALC lines.
this file has a lot of code and i have to extract all blocks of LIN to ALC lines.

Posted: Sat Feb 03, 2007 5:52 am
by raghavan20
feyd wrote:"m" (multiline) mode makes it look for a single line.
even if i take m off, it still does not work feyd.

Posted: Sat Feb 03, 2007 8:00 am
by feyd
The default is multiline mode. You want the "s" modifier.

Posted: Sat Feb 03, 2007 2:08 pm
by raghavan20
feyd wrote:The default is multiline mode. You want the "s" modifier.
oh yes feyd, it worked.
its been a long time i worked with regex, i forgot the modifier character. Thank you.

Posted: Sat Feb 03, 2007 3:48 pm
by Ollie Saunders
You probably want to wrap the .*? in () too