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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -