Jump to content

Regex help matching several words in one long text


chrisran

Recommended Posts

Hi !

 

I've got a very long text like this:

 

$var = "Blabla text text text [...] bla bla text text some weird text NEWCU - NEW Customer 0 -> 1 <br /> AMWHA - Some Description 0 -> 2 <br />  INST3 - Install Services 1 <br /> MORES - More Services 0 -> 1 <br /> bla bla bla text text text";

 

In my script I now have these keywords (NEWCU, AMWHA, MORES) set to 0 by default:

 

$newcu = 0;

$amwha = 0;

$mores = 0;

 

Now I'd like to set them to the value after the corresponding -> so for example NEWCU gets 1, AMWHA gets 2 and MORES gets 1.

 

How do I preg_match that ?

 

$newcu = preg_match("/NEWCU - [^] (.?) -&gt (.?)/",$var); <-- does not work.

 

I'd like to grep on "NEWCU -" then skip everything until the -&gt and put the first digit before -&gt (here 0) into $newcu[1] and the digit after -&gt into $newcu[2]..

 

Anyone an idea ? :)

 

Thanks

 

 

Thanks for your reply mike, but it does not work this way:

 

I wrote a small testprogram to check:

 

 

$string = "NEWCU - Cust No 331351    0 -> 1";

$newcu = preg_match("/NEWCU - [^0-9]*([0-9]+) -> ([0-9]+)/",$string, $matches);
$first = $matches[1];
$second = $matches[2];

echo "<BR><BR>NEWCU: $newcu ] $first -> $second<BR><BR>";

 

 

Result:

NEWCU: 0 ] ->

 

 

Any Idea ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.