Skip to main content
I having having troubles creating a regex query in the Text Editor. I am evaluating an xml File which contains WKT Geometries. I am creating another attribute with the "Attribute Creator" which checks the "Geom" Field in the data and writes in a new column whether the geometry is POINT, POLYGON, MULITPOLYGON etc. I need to use regex to differentiate between "POLYGON ("and "MULTIPOLYGON (" because when I search for "POLYGON (" all the "MULTIPOLYGON ("s will be found.

 

 

So I opened the Advanced text editor so I can use simply "/bPOLYGON ("which searches for the string "POLYGON" at the start of a word...but I can´t understand the editor syntax.

 

 

The documentation states... 

 

 

 "FindRegEx(string str, string regExp, .int startIdx], /bool caseSensitive],  -1])"
 

 

and my TextEditor shows...

 

 

 @FindString(<STRING>,<STRING>)POLYGON (
 

 

What does "string str"" mean? What does "string regExp," mean...Could anyone give me an example of how I should use the Advanced Editor?

 

 

 

 

Hi,

 

 

In this case, "string str" means a character string to be tested, and "string regExp" means a regular expression. For example, if an attribute called "wkt" stores the WKT (i.e. a character string to be tested), this expression returns the position (0-based index) of the part matched with "POLYGON" (i.e. regular expression). If not matched, returns -1.

 

-----

 

@FindRegEx(@Value(wkt),POLYGON)

 

-----

 

 

However, if you need to determine if the string contains which one of "POINT", "POLYGON", "MULTIPOLYGON" etc., I think that "Conditional Value" setting is simpler than the @FindRegEx function. For example:

 

 

 

Just be aware that you should test MULTIPOLYGON before POLYGON, since the test conditions will be evaluated in the order from top to bottom.

 

 

Takashi
OK...thanks for the reply. so @Value(wkt) indicates that the AttributeField is Value because it is preceded by the @Value()? Where is this documented?
See here.

 

http://docs.safe.com/fme/html/FME_Workbench/Default.htm#transformer_parameters/Feature_Functions.htm

 

 

If you double-click or drag-and-drop the attribute name shown in FME Feature Attributes section, @Value(<attribute name>) will be added to the editor pane. 

 

 


For the following string

 

 POINT (9.9699121998145532 52.9278245931941953)
 

 

RegEx works when I enter 

 

 ^POINT.*
 

 

But not when I use...

 

 ^POINT \(
 and NOT when I write

 

 ^POINT\s\(
 BUT...it works when I write

 

 POINT\s\(.*
 Can you explain this?

 

 

 


.* is 0 or more of any character 

 

 

^POINT\\s\\(             looks for a string ending with a ( 

 

wich it does not

 

POINT\\s\\(.*            looks for a string ending with any character

 


If u going to use more regexp

 

http://www.tcl.tk/man/tcl8.4/TclCmd/re_syntax.htm

 

 

 

there are many sites on this topic and for all flavors.
Didn't you get this error message?

 

AttributeCreator: Unable to find closing bracket for function FindRegEx in

 

 

If the string literal to be passed to FME Function contains a paren, it should be quoted, like this. # This seems not to be documented.

 

-----

 

@FindRegEx(@Value(wkt),"^POINT \\(")

 

-----

 

I think the last expression will be also fail if it isn't quoted.
@FindRegEx(@Value(tsstr),^POINT \\()

 

 

does indeed yield error  AttributeCreator_2: Unable to find closing bracket for function FindRegEx

 

 

But it does not stop the proces, you just get "@FindRegEx(@Value(tsstr),^POINT \\()" as outputstring.

 

Same goes for the last one indeed: POINT\\s\\(.*

 

 

 

@FindRegEx(@Value(tsstr),^POINT \\((O\\d\\.\\s]*\\))) works with no quotes. Parens are balanced.

 

 

Also, often u need to use braces {}, when it contains reserved characters. But only when u dont wan't it to parse anything in the string.
Admittedly I´m no RegEx Expert, but I tested the regex here (http://regex101.com/)

 

 

if I use this as a test string

 

 POINT (9.9699121998145532 52.9278245931941953)
 and use the expression...

 

 

 ^POINT\s\(
 

 

without .*, then I get a match! I only want to match POINT\s\(....why do I need .*?

 

 


there are different flavors of regexp.

 

 

It does not mean it wil work in the transformer. To see if it works in the transformer you must run it. (i use RUbulator a lot, but Rubulator can use like 3 flavors or so).

 

 

If u want more options or possibility u can use a attribute creator and use tcl

 

So in stead of using FindRegEx

 

 

u can use aregexp {exp} @Valeu(str)] this has a lot of ooptions. Look at

 

 the link i send u. Almost all on that site work here.

 

U can also use other tcl functions this way.

 

 

 

without .*, then I get a match! I only want to match POINT\\s\\(....why do I need .*?

 

 

Because your string has mote items beyond the "(" so it wil not match.

 

 

and of course

 

 

regular expressions 101

 

— an online regex tester for javascript, php, pcre and python

 

wich is not the same as what is used in FME or tcl etc.

 


Reply