regex - Attach a string to every group of substrings separated by a set of symbols -


imagine have string

newton = 'kg*m/s^2' 

and need be:

newtonmupad = 'unit::kg*unit::m/unit::s^2' 

is there simple way detect every physical unit , attach unit:: it? can assumed every unit seperated either /, * or exponent ^2 or ^3.

for used several regular expressions, like

x = regexp(newton ,'*','split') y = regexp(newton ,'/','split') z = regexp(newton ,'^','split') 

and i'm able create string need loop. wonder if there simpler , faster solution using matlab?

you can use regexprep:

>> newton = 'kg*m/s^2' >> regexprep(newton,'(([a-za-z]+)(*|/|\^|$))', 'unit::$1')  ans =   unit::kg*unit::m/unit::s^2 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -