regex


Interpreting powers in perl using regex


I'm trying to read in two numbers separated by a : and perform a comparison.
Below is some code that illustrates my problems:
use strict;
use warnings;
my #nums = qw(1.23:2.13 0.1:2.11 1.17772e+06:1.32 2:10.2);
for my $number (#nums){
print "actual numbers $number\n";
my ($c, $e) = ($1, $2) if $number =~ /(\d+\.\d+|\d+):(\d+\.\d+|\d+)/;
print "regex matches: $c:$e\n";
}
Which outputs:
actual numbers 1.23:2.13
regex matches: 1.23:2.13
actual numbers 0.1:2.11
regex matches: 0.1:2.11
actual numbers 1.17772e+06:1.32
regex matches: 06:1.32 # not capturing 1.17772e+06
actual numbers 2:10.2
regex matches: 2:10.2
My question is: How can I a) capture 1.17772e+06 and b) evaluate it as a number?
From perldata:
/^(?:[+-]?)(?=\d|\.\d)\d*(?:\.\d*)?(?:[Ee](?:[+-]?\d+))?$/
Or,
use Regexp::Common;
/$RE{num}{real}/
(These assume you want Perl's definition of a number.)
I would just use the split function (split /:/) here.

Related Links

Python & Regex: Match all, but not when x or y
replace with gsub in R
Htaccess to change Root image path?
Regex Match between brackets (…)
Vexing regex pattern
String search Regular expressions VB? [duplicate]
merging two data sets on the basis of two columns
How to get sed to take extended regular expressions?
Looping through a list of regex matches and grabbing the first capture group in a loop
Counting occurence with a condition using awk
Find specific date match use of regular expression in shell?
Alter Varnish TTL based on Request URL
r stringdist or levenshtein.distance to replace strings
Regex to Select All Text in String Before Substring
Scala Regex for less than equal to operator (<=)
Capture groups inside string using regular expression

Categories

HOME
math
lsf
unit-testing
clojure
word-vba
libreoffice
robot
encog
format
whitespace
apple-mail
tin-can-api
h2o
square-connect
vscode-settings
smartsheet-c#-sdk-v2
partitioning
qualtrics
accumulo
jquery-selectors
html-email
gas
git-bash
windows-applications
co
cadvisor
padding
scalability
phonegap-desktop-app
temp
swipe
subtotal
vrtk
xaf
macvim
decompiler
cookiestore
word-embedding
logicblox
easy-digital-downloads
hawkular
linear
mdanalysis
couchbase-lite
gulp-babel
requirements-management
ms-jet-ace
dump
laravel-routing
ios-app-group
biological-neural-network
tryton
gpt
angular-directive
bosh-deployer
replicate
callkit
tachyon
logstash-jdbc
xceed
visual-build-professional
vlc-android
sql-server-2016-express
dms
selenium2library
ota
mars
kinto
jedi
post-processor
xirr
interpreted-language
user-registration
telescope
bonfire
diagonal
getuikit
mks
mklink
formhelper
cpp-netlib
syndication-feed
bonecp
nawk
transport-stream
shift
libnids
wow64
chromeless
northwind
dynamic-usercontrols
jcycle
lungojs
datakey
time-limiting
obout
objcopy
katta
textboxlist
blackberry-jde
codi
pastebin
remote-control
sloc
nhaml
roguelike

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App