span8
span4
span8
span4
Here are two possible strategies.The first is using a StringSearcher with the following regexp: (.+)_ It basically takes all the characters up until the last underscore and puts them into a result group,by default contained in a list called "_matched_parts".You can then use a ListIndexer to extract "_matched_parts{0}" which would contain the desired part,defined by the parenthesis in the regexp.
Since I'm a big fan Python,here is also a solution that does the same,but without the need for a ListIndexer:
import fmeobjectsdef get_filename_part(feature): ecw_filename = feature.getAttribute("ecw_filename") last_underscore_pos = ecw_filename.rfind("_") first_part = ecw_filename[:last_underscore_pos] feature.setAttribute("first_part",first_part)
The code above creates a new attribute called "first_part" that contains all the characters before the last underscore in the attribute "ecw_filename".You can expose "first_part" in the PythonCaller's "Attributes to expose" to make it visible in your workspace.
David
ok,now it's 2018,can I just do this in the AttributeManager with the text editor?
lol Takshi you reactivated old one...2012!!
But,okay..here..
use stringreplacer
search for
(.+[-_]+.+)\_\d+.(ecw)
replace with
\1\2
The StringReplacer with this setting could also be a solution in the current version of FME that uses better regex engine than before.
To all who have answered so far...
Wow.Sincerely.Thank you for such quick responses.However,I have made a classic "user mistake" by not being a bit more specific about the filenames I will be processing.They can be just about any format prior to the last underbar so you could see:
ABC_0123.ECW, A-B_C_123.ECW, 001-ABC_DEF_012.ECW
However,after the last underbar in the string along with the remaining digits (minus the file extension .ECW) is what I want stripped off leaving me:
ABC.ECW, A-B_C.ECW, 001-ABC_DEF.ECW
I was thinking about possibly reversing the string and then removing everything up to and including the first underbar,reversing it again and adding back the .ECW.I just am not sure how to do that?Does that simplify the solution?
Thanks again!You guys are great!
© 2019 亚搏在线Safe Software Inc |Legal