matlab - How to define a regex that matches whole words treating "." like a normal letter -
i trying read several numbers string in matlab. aim str2num
does, without using eval
(and less advanced).
i have regex matching valid double number:
'([-+]?([0-9]*\.[0-9]+|[0-9]+\.|[0-9]+)([ee][-+]?([0-9]*\.[0-9]+|[0-9]+\.|[0-9]+))?)'
which works fine valid substrings such "1.15e2.4". problem want avoid matching invalid substrings such "1.15.e2.4" (which splits "1.15" , "2.4").
when match whole words (using \<
, \>
), invalid string split "1.15" , "4"), because decimal point considered word binary.
for using look-around expressions:
'((?<=^|[ :,])[-+]?([0-9]*\.[0-9]+|[0-9]+\.|[0-9]+)([ee][-+]?([0-9]*\.[0-9]+|[0-9]+\.|[0-9]+))?(?=$|[ :,]))'
but wonder if there easier , more general way.
is possible redefine characters considered word boundaries?
you cannot redefine word boundary means. can achieve same effect using negative lookarounds:
(?<!\.)\< first regex here \>(?!\.)
not dramatically simpler second regex, more robust since says: disallows .
word boundary.
Comments
Post a Comment