New submission from Mallinath Akkalkot <[email protected]>:
Issue is explained in the attached presentation for the below python script.
# PYTHON script
import re
stringPassed = "START, 0.272342208623734, 0.122712611838329\nCIRCL, 0.2739,
0.1175, 0.2644, 0.1175\nCIRCL, 0.2644, 0.108, 0.2644, 0.1175\nLINE,
0.26237716818855, 0.108\nCIRCL, 0.2564, 0.102522934456486, 0.26237716818855,
0.102\nLINE, 0.255041919210401, 0.087\nLINE, 0.255041919210401, 0.072\nCIRCL,
0.239541747114243, -0.0106446715786942, 0.0269671265080016,
0.0720000000000296\nCIRCL, 0.2391, -0.0130000000000008, 0.2456,
-0.0130000000000008\nLINE, 0.2391, -0.0350000000000008\nCIRCL,
0.243376868486329, -0.0411080018232587, 0.2456, -0.0350000000000008\nLINE,
0.24865951460066, -0.0430307277670375\nCIRCL, 0.255041919210401,
-0.0521457461886608, 0.245341919210401, -0.0521457461886608\nLINE,
0.255041919210401, -0.087\nLINE, 0.2564, -0.102522934456486\nCIRCL,
0.26237716818855, -0.108, 0.26237716818855, -0.102\nLINE, 0.2644,
-0.108\nCIRCL, 0.2739, -0.1175, 0.2644, -0.1175\nCIRCL, 0.272342208623734,
-0.122712611838329, 0.2644, -0.1175\n"
retVal = re.findall(r"(\w+,\s+)(-\d+\.\d+)|(\d+\.\d+)", stringPassed,
re.MULTILINE)
floatNumbersList = [] # List conatins all Folat numbers
for each in retVal:
for each in each:
if each != "":floatNumbersList.append(each)
newStringUpdated = stringPassed
for eachVal in floatNumbersList:
newVal = str(float(eachVal)*1000)
retVals = re.sub(eachVal, newVal, newStringUpdated)
# retVals = newStringUpdated.replace(eachVal, newVal)
newStringUpdated = retVals
print(newStringUpdated)
----------
components: Regular Expressions
files: Bug_Description_Regular Expression.pptx
messages: 351066
nosy: Mallinath Akkalkot, ezio.melotti, mrabarnett
priority: normal
severity: normal
status: open
title: Results with re.sub and re.replace is giving different results
type: behavior
versions: Python 3.7
Added file: https://bugs.python.org/file48584/Bug_Description_Regular
Expression.pptx
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue38016>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com