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:
a1should returnaa1:d10should returnaad10should returnadad1:bbb1should returnad
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
Post a Comment