REGEXPR_REPLACE字符串

时间:2016-09-30 09:13:47

标签: sap hana hana-sql-script

如何替换以下字符串中的&

'extends the functionality & of the & REPLACE function & by'

分别为onetwothree

最后结果应该是:

extends the functionality one of the two REPLACE function three by

2 个答案:

答案 0 :(得分:1)

(有点晚,但是)一个版本使用一个REPLACE_REGEXPR:

// Your original intent
Intent intent = new Intent(Intent.ACTION_VIEW);

// Configure your original intent as per usual here...

// Build a chooser intent based on your original intent
String title = getResources().getString(R.string.chooser_title);
Intent chooser = Intent.createChooser(intent, title);

// Verify the intent will resolve to at least one activity
if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity(chooser);
}

输出:

SELECT
    REPLACE_REGEXPR(
        '([^&]*)&([^&]*)&([^&]*)&([^&]*)'
        IN 'extends the functionality & of the & REPLACE function & by'
        WITH '\1one\2two\3three\4') "replace_regexpr"
FROM DUMMY
;

答案 1 :(得分:0)

你可以做一个嵌套的REPLACE_REGEXPR函数,并且总是用不同的字符串替换第一个(下一个)剩余匹配。

SELECT REPLACE_REGEXPR
       ('&' IN REPLACE_REGEXPR 
               ('&' IN REPLACE_REGEXPR
                      ('&' IN 'extends the functionality & of the & REPLACE function & by'
                        WITH 'one' OCCURRENCE 1) 
                 WITH 'two' OCCURRENCE 1)  
         WITH 'three' OCCURRENCE 1) "replace_regexpr" 
FROM DUMMY;
相关问题