tags:

views:

83

answers:

2

I have a list of steps, and they are being echo'd into the view as li items in a ol.

So, I need to remove leading numbers (that look like ol { list-style: decimal }.

Here is an example array member

  1. Combine 1 tbs oil...

I tried this regex

/^\d+\.\s*/

However, it didn't remove the 1. in the example above

But, when I remove the start of line anchor (^), it works.

Here is the complete code.

foreach($method as &$step) {

    $step = trim(preg_replace('/^\d+\.\s*/', '', $step));
    var_dump($step); // This is what I quoted above
}

What am I doing wrong?

Thanks!

Update

Sorry guys, here is a var_dump() of one of the lines..

string(43) "4. Remove from heat and cover to keep warm."

To me, it doesn't look there is anything before the digit.

+3  A: 

is there any whitespace before the digit?

Try

/^\s*\d+\.\s*/
Luke Schafer
That worked, however, I couldn't see any whitespace there. I probably should of converted `\s` into something so I could see better. Cheers for the answer, I knew it would be something silly.
alex
+1  A: 

There's probably extra whitespace around. Also you can get ^ to change its behavior with the m modifier:

<?php
$s = <<<EOS
  1. Combine 1 tbs oil...
  2. Hello World
  3. Ok then!
EOS;
echo trim(preg_replace('/^\s*\d+\.\s*/m', '', $s));
pygorex1
Thanks, I knew about `m`, but I already has these values in an array. +1
alex