Skip to main content
Solved

If then regex in StringReplacer


geolassi
Contributor
Forum|alt.badge.img+5

Hello group! I've been trying to replace a string with StringReplacer, if the text line contains certain text. So basically it's a classic ifthen conditional in regex, though I'm new to conditional tests in regex.

My text string is:

#1=IFCCARTESIANPOINT((1,1));

If the text string contains IFCCARTESIANPOINT then search for ));.

I tried syntax (?(A)X), If A then X, thus my regex:

(?(IFCCARTESIANPOINT)[)][)];) but it doesn't work at all.

I'd very much appreciate help :)

Best answer by ebygomm

The syntax you are using tests for if something is preceded by, not if the line in general contains the text. There are some additional characters before your text string which you need to handle. If you don't know what they are something like this would work in a string replacer. The .* matches but doesn't return everything between IFCCARTESIANPOINT and the ));

(?<=IFCCARTESIANPOINT).*(\)\);)

 

Edit: the above doesn't appear to work in FME. You can capture the extra characters separately then reinsert however

(?<=IFCCARTESIANPOINT)(.*)(\)\);)

Replacement text needs to be \1 followed by whatever you want to replace the )); with

0684Q00000ArJd9QAF.png

View original
Did this help you find an answer to your question?

2 replies

ebygomm
Influencer
Forum|alt.badge.img+39
  • Influencer
  • Best Answer
  • May 1, 2019

The syntax you are using tests for if something is preceded by, not if the line in general contains the text. There are some additional characters before your text string which you need to handle. If you don't know what they are something like this would work in a string replacer. The .* matches but doesn't return everything between IFCCARTESIANPOINT and the ));

(?<=IFCCARTESIANPOINT).*(\)\);)

 

Edit: the above doesn't appear to work in FME. You can capture the extra characters separately then reinsert however

(?<=IFCCARTESIANPOINT)(.*)(\)\);)

Replacement text needs to be \1 followed by whatever you want to replace the )); with

0684Q00000ArJd9QAF.png


geolassi
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • May 2, 2019
ebygomm wrote:

The syntax you are using tests for if something is preceded by, not if the line in general contains the text. There are some additional characters before your text string which you need to handle. If you don't know what they are something like this would work in a string replacer. The .* matches but doesn't return everything between IFCCARTESIANPOINT and the ));

(?<=IFCCARTESIANPOINT).*(\)\);)

 

Edit: the above doesn't appear to work in FME. You can capture the extra characters separately then reinsert however

(?<=IFCCARTESIANPOINT)(.*)(\)\);)

Replacement text needs to be \1 followed by whatever you want to replace the )); with

0684Q00000ArJd9QAF.png

Thank you very much @egomm! It would've taken so much time to figure that out. It works perfectly.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings