I have a text field xyz which can contain any one word.
I want a new field which shows the content of xyz without the last two letters in it, ie "january" as "janua", "july" as "ju"...etc...
Left (field ; Length(field) - 2)
Sent from miPhone
Or, if there could be spaces...
But of course! The return-at-the-end-of-the-field is another "gotcha" that I need to fix sometimes.
Returns are for typewriters :)
Not to get too far off topic, I hope, but one thing I really like about Python is that you can just start writing code. And, that code can be as simple or as complex as necessary. (MIT now using Python for programming classes)
To prototype more advanced string replacements, I like the Python console.
(Then I could call that python code directly from FMP.)
Examples below show regex and also the simpler replace (recommended unless you need regex) right in the interactive python console you can run at your terminal.
Like Java (and other modern languages), python lets you compile ReExes for performance.
Example: Extract only lower case alphabetic characters and no spaces:
s = 'this! is!! some! text# #### with $$$ spaces and other characters&#&@(! 'com = re.compile("[a-z]|^\s*]+")
f = com.findall(s)
>>> Prints: thisissometextwithspacesandothercharacters
Deciding when to use a regex or simpler string replace shouldn't be dictated, IMHO, by the tool you're using (since most all tools support regex). Fortunately, FMP gives us lots of ways to extend its missing functionality.
I threw in all this extra stuff since there's really no end to what we need to do with strings.
To wit, without RegEx capability, working with strings (obviously this posting was beyond simple) can be a difficult (and unnecessary with modern tools) forcing you to write often nasty procedural (often difficult to maintain) code instead of a simpler RegEx expression that can (additionally, when needed) be compiled.
Retrieving data ...