Regex to extract nth token of a string separated by pipes

前端 未结 2 1550
执笔经年
执笔经年 2021-01-24 15:16

I\'m new in Regex

I need to count and extract tokens from the below sample text:

AA||CCCCCCCC|||FFFFFFFFFFF

Requesting 4th token I mus

2条回答
  •  忘掉有多难
    2021-01-24 16:04

    For DB2 please try this to get the 6th element in the list. This works on Oracle and allows for NULL list elements. The syntax for the REGEXP_SUBSTR call is the same so I suspect it will work:

    regexp_substr('AA||CCCCCCCC|||FFFFFFFFFFF', '(.*?)(\||$)', 1, 6, 'c', 1)
    

    EDIT: 'c' for case-sensitive

提交回复
热议问题