Question

Isolate a specif number


Hi, my problem is I need to isolate a specific number in a sentence like those number in highlight, but I really don't know because is not the same sentence everytime :

 

La 00132-12-095 est issue de la 00132-12-090

(décret 50_459-2013)

or

Elle est issue de la 43860-01-030

(décret modificatif 1168-2003) qui est issue de la 43860-01-000 (décret modificatif

529-2002) 

or La 48375-01-030 est issue de la "-"-000

(the real number I need to isolate is 48375-01-000)

 

 


5 replies

Userlevel 4
Badge +25

If the number always has that format (5 digits, a dash, 2 digits, a dash and 3 digits) you could use a regular expression in a StringSearcher. 

\d{5}\-\d{2}\-\d{3}

 as a regex should do it. It should come up with multiple matches so make sure to set a matches list name. Based on your examples I assume the last element in that list is the one value you need.

Badge +20

Use the regular expression [0-9]{5}|[-]|[0-9]{2}|[-]|[0-9]{3} to filter the kind of pattern you mentioned.

If you want to put it into an attribute you have to process your string first, split it by " " (space character) and filter the list via the regular expression above.

Badge +2

@wabafou​ is it always the last issue number in the sentence that you need to extract?

yea most of the time that why it's difficult, because in RegExr you can't said "select de last one"

Badge +2

@wabafou​ regex does allow you to "select the last one' using the lookaround options for lookahead and lookbehind. But I find these pretty hard to figure out.  

But in StringSearcher,  you can use subexpressions and then, in this case, find the last of the subexpression that matches. So for your string:

La 00132-12-095 est issue de la 00132-12-090

you can use the regex that @Hans van der Maarel​ suggested, but wrap it in () to make it a subexpression:

(\d{5}\-\d{2}\-\d{3})

Then in StringSearcher, under Advanced, enter  Subexpression Matches List Name.  This will return a list of the patterns that were matched, something like this;

Attributes (12)
    _creation_instance 0
    _element_count 2
    _first_match 00132-12-095
    _sub_expression{0}.part 00132-12-095
    _sub_expression{0}.startIndex 3
    _sub_expression{1}.part 00132-12-090
    _sub_expression{1}.startIndex 32
    attr La 00132-12-095 est issue de la 00132-12-090

Then you can select the last element in the list _sub_expression{}.part.

If you also include a pattern to find "-"-000:

(\d{5}\-\d{2}\-\d{3})|(\"-\"-000)

you should be able to get what you want. 

I'll leave it to you to figure out how to replace the parts of "-"-000 with elements from the previous number using AttributeSplitter.

I've attached an example workspace (FME 2021.0)

 

 

 

 

Reply