Replace string using regular expression in KETTLE

点点圈 提交于 2019-12-12 04:24:28

问题


I would like to use regular expression for replacing a certain pattern in the Kettle. For example, AAAA >5< BBBB, I want to replace this with AAAA 555 BBBB. I know how to find the pattern, but I am not sure how to replace that with new string. The one thing I have to keep is that I have to find pattern together ><, not separately like > or < because there is another pattern <5>.


回答1:


You can use the "Replace in String" step in a transformation.

Set use RegEx to "Y", type your regex on the Search box, with capturing groups if necessary, and the replacement string in the replacement box, referring to capture groups as $1, $2, ...

It'll replace all occurrences of the regex in the original string.

If the Out Stream field is ommitted, it'll overwrite the In stream field.




回答2:


If you want the pattern >\d< replaced by a triple of the found digit, you can use Replace-In-String in regex mode:

Search:     (.*)(>(\d)<)(.*)
Replace:    $1$3$3$3$4

If you want all such patterns treated the same:

Search:     (>(\d)<)
Replace:    $2$2$2

EDIT due to your improved requirement

Since you intend to convert your "simple" markup to a more HTML-like markup, you better use a User-Defined-Java-Expression. Also, you must avoid to reintroduce simple markup when replacing repeatedly.



来源:https://stackoverflow.com/questions/42280581/replace-string-using-regular-expression-in-kettle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!