Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for numbers on scientific notation?

Tags:

c++

regex

I'm loading a .obj file that has lines like

vn 8.67548e-017 1 -1.55211e-016

for the vertex normals. How can I detect them and bring them to double notation?

like image 755
andandandand Avatar asked Dec 18 '10 18:12

andandandand


People also ask

What does '$' mean in regex?

$ means "Match the end of the string" (the position after the last character in the string). Both are called anchors and ensure that the entire string is matched instead of just a substring.

Can regex be used for numbers?

The regex [0-9] matches single-digit numbers 0 to 9. [1-9][0-9] matches double-digit numbers 10 to 99. That's the easy part. Matching the three-digit numbers is a little more complicated, since we need to exclude numbers 256 through 999.

How do you represent a number in regex?

\d (digit) matches any single digit (same as [0-9] ). The uppercase counterpart \D (non-digit) matches any single character that is not a digit (same as [^0-9] ). \s (space) matches any single whitespace (same as [ \t\n\r\f] , blank, tab, newline, carriage-return and form-feed).

What does D+ mean in regex?

\d is a digit (a character in the range [0-9] ), and + means one or more times. Thus, \d+ means match one or more digits. For example, the string "42" is matched by the pattern \d+ .


1 Answers

You can identify the scientific values using: -?\d*\.?\d+e[+-]?\d+ regex.

like image 152
Asha Avatar answered Sep 30 '22 19:09

Asha