A string replacer using regex is probably a more straightforward way to do the replacement. Although I don't think your regex does what you want it to.
((?<=[A-Z])\s(?=[A-Z]\b))|(\s(?=\,))
If you want to remove the spaces between the single letters but not the words you will need something like. This is removing spaces that are preceded by a single character and followed by a single character and which come before a comma. This works for your single example but depending on other values in your data, you may need something slightly different.
If you really wanted to use a pythoncaller (*note the slightly different regex)
import fme
import fmeobjects
import re
def processFeature(feature):
string4 = feature.getAttribute('POINT_NAME')
newpointname = (re.sub('((?<=[A-Z])\s(?=[A-Z]\\b))|(\s(?=\,))', '',string4))
feature.setAttribute('NEW_POINT_NAME', newpointname)
A string replacer using regex is probably a more straightforward way to do the replacement. Although I don't think your regex does what you want it to.
((?<=[A-Z])\s(?=[A-Z]\b))|(\s(?=\,))
If you want to remove the spaces between the single letters but not the words you will need something like. This is removing spaces that are preceded by a single character and followed by a single character and which come before a comma. This works for your single example but depending on other values in your data, you may need something slightly different.
If you really wanted to use a pythoncaller (*note the slightly different regex)
import fme
import fmeobjects
import re
def processFeature(feature):
string4 = feature.getAttribute('POINT_NAME')
newpointname = (re.sub('((?<=[A-Z])\s(?=[A-Z]\\b))|(\s(?=\,))', '',string4))
feature.setAttribute('NEW_POINT_NAME', newpointname)
Thanks @egomm.. I will test this.
Considering different cases
they could be as below.
Test caseExpected outputtext
Space Comma text commatext
Space comma Spacetext comma spacetext Comma
Space Commatext comma spacetext
Double commatext commatext comma
dot texttext comma texttext hypen commatext comma
Thanks again!
Cheers,
BokaJ
A string replacer using regex is probably a more straightforward way to do the replacement. Although I don't think your regex does what you want it to.
((?<=[A-Z])\s(?=[A-Z]\b))|(\s(?=\,))
If you want to remove the spaces between the single letters but not the words you will need something like. This is removing spaces that are preceded by a single character and followed by a single character and which come before a comma. This works for your single example but depending on other values in your data, you may need something slightly different.
If you really wanted to use a pythoncaller (*note the slightly different regex)
import fme
import fmeobjects
import re
def processFeature(feature):
string4 = feature.getAttribute('POINT_NAME')
newpointname = (re.sub('((?<=[A-Z])\s(?=[A-Z]\\b))|(\s(?=\,))', '',string4))
feature.setAttribute('NEW_POINT_NAME', newpointname)
Hi @egomm,
I tried the pythoncaller statements and it was giving me error
"Python Exception <TypeError>: expected string or buffer"
I edited the code to pass string instead of list object and now it works fine.
import fme
import fmeobjects
import re
def processFeature(feature):
string4 = feature.getAttribute('POINT_NAME')
newpointname = ""
for row in newpointname:
for cell in row:
newpointname = (re.sub('((?<=[A-Z])\s(?=[A-Z]\\b))|(\s(?=\,))', '',string4))
feature.setAttribute('Corrected_POINT_NAME', newpointname)
Thanks again for the foundation!
Cheers,
BokaJ