php - Get all letters before the optional colon -


i have wrapper phpexcel, , have method called setcolumn(), looks this:

public function setcolumn($cell = ""){     if(empty($cell)){         $cell = $this->cell;     }     $this->column = strtoupper(preg_replace("/[^a-za-z]/", "", $cell));     $this->cell   = "{$this->column}{$this->row}";     return $this; } 

it works fine, use it, can pass in ranges such a1:d1 , when do, preg_replace not replace correctly, return ad don't want. want return a. not sure of regular expression needed accomplish this.

the parameter $cell can contain few different values:

  • a1 should return a
  • a1:d10 should return a
  • ad10 should return ad
  • ad1:bbb1 should return ad

the list go on, basics. can acomplish that?

matches digit optional colon after that

preg_replace("/\d:?.*/", "", $cell);  

or linepogl points out just

preg_replace("/\d.*/", "", $cell);  

as long pattern stays: letter(s) number everythingelse


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -