What does the text and the pattern in question look like?
Because we have so many functions to be as flexible as possible.
I'm assuming you've already tested your RegEx using a tool like RegExRx or similar.
If you're not sure what's going on with your RegEx itself, please post it and some text you need it to match.
Lots of folks here on the forum can definitely help you with that.
Here is the example text:
and I would like to extract the parameter "seller" which is: A2XKMLJ9HIY1T
The regex patten is: seller=(.*)
That RegEx looks fine as long as nothing ever comes after the seller's ID.
Since I don't use MBS, Christian can reply how to do what you want using that tool.
How I do RegEx processing from FMP, however, is using a small external Java service I wrote.
The steps include:
- Use FMP's GetAsUrlEncoded function to pre-process the RegEx expression,
- Pass the RegEx to the service (INSERT FROM URL),
- Pass the text to be searched to the service (INSERT FROM URL),
- Do the RegEx -- all behind the scenes--all complexity hidden (abstracted) as it should be.
In the screenshot below (click on it if you can't see all of it), you enter the String you want to search (first field), and the RegEx (second field). Then, when I TAB off the second field (the one with the "(2)" in the screenshot below), the service receives the string to search (via INSERT FROM URL, POST method) and the encoded RegEx and SIMPLY returns the matched text, if any.
Plus, this service will return a "return-delimited" list if there's more than one match so you can then use FMP's GetValue() function to extract just the one(s) you want from FMP.
SIMPLE. SIMPLE. SIMPLE.
Abstracted (messy RegEx details completely hidden. Beyond entering the RegEx and entering the source text, there's nothing to know or do beyond data entry itself).
UPDATE - June 10, 2017: Changed layout so no intermediate field necessary.
Now, just enter the string to search, enter the RegEx, and pres TAB. That's it!
The RegEx automatically appears (nearly) "instantly".
(Note: The RegEx is compiled too using this method.)
There are pluses and minuses for FMP plug-ins others sell vs external services like I wrote so it always depends on the situation.
Although a major benefit of a FMP plug-in is that it's "always there", services like I wrote have these benefits:
1. Cross platform so the service can reside ... anywhere (Linux, Mac, Win). Local/WAN, Server, you name it.
2. Allow any application that can do a GET to use the service (Terminal, FMP, Firefox, Opera, Chrome, ....)
(POST or other HTTP verbs also supported.)
3. Is FREE. No expensive FMP-ONLY plug-in(s) needed . Install anywhere or everywhere. 1 user or 10,000 users. FREE.
4. Means there is no FMP plug-in installation and configuration for every copy of FMP you might have
5. Means no restrictive plug-in license agreements
6. Extremely powerful (get the full power of Java + free third-party libraries like Apache and others.)
7. Put you in charge of the service code. Not a third party.
8. Are ... FAST!
9. Externalize loops in Java to keep loops out of slow FMP scripts.
10. You could email the service JAR file to others and they could use it right away (assuming Java installed, etc.)
the link you posted is kinda deadly.
1 of 1 people found this helpful
Here you go:
pattern = "^http.*\?.*&seller=(.*)$";
regex = MBS( "RegEx.Compile"; pattern; 512+1 );
r = MBS( "RegEx.Execute"; regex; text; 0 );
r = MBS( "RegEx.Substring"; regex; 1 );
f = MBS( "RegEx.Free"; regex )
] ; r )
All in one let statement, but this can be put in a Custom Function or a script.
The compiled regular expression can be reused for as many matches as you need (which makes it much faster!).
3 of 3 people found this helpful
Using the free LuaFy plug-in, the pattern matching expression is a one-liner.
LuaFy_CallFunction("string.match"; YourText; "seller=(%w+)")
will return A2XKMLJ9HIY1T
when YourText is
I chose %w+ which is one or more alphanumeric characters to better fit the seller ID instead of .* which would be zero or more of any character.
Note that Lua's built-in pattern matching engine is different than RegEx. Lua's is more streamlined.