say have string contains units (which may or may not have prefixes) want break individual units. example string may contain "btu(th)" or "btu(th).ft" or "mbtu(th).ft" mbtu(th) bastardised unit milli thermochemical btu's (this purely example).
i have following (simplified) regex fails case "mbtu(th).ft":
/(m|k)??(btu\(th\)|ft|m)(?:\b|\s|$)/g currently not correctly detect boundary between end of 'btu(th)' , start of 'ft'. understand javascript regex not support how accurately parse string?
additional notes
- the regex presented above simplified around prefixes , units groups. prefixes span multiple characters 'ki' , therefore character sets not suitable.
- the desire each group catch prefix match group 1 , unit match 2 i.e 'mbtu(th).ft' match 1 ['m','btu(th)'] , match 2 ['','ft'].
- the prefix match needs lazy string 'm' matched unit metres rather prefix milli. likewise match 'mm' need prefix milli , unit metres.
i try with:
/((m)|(k)|(btu(\(th\))?)|(ft)|(m)|(?:\.))+/g at least example above, matches units merged 1 string. demo
edit
another try (demo):
/(?:(m)|(k)|(btu)|(th)|(ft)|[\.\(\)])/g this 1 again match 1 part, if use $1,$2,$3,$4, etc, (demo) can extract other fragments. ignores ., (, ), characters. problem count proper matched groups, works degree.
or if accept multiple separate matches think simple alternative is:
/(m|k|btu|th|ft)/g
Comments
Post a Comment