Last word in a sentence: In SQL (regular expressions possible?)

后端 未结 5 1486
夕颜
夕颜 2020-12-19 14:32

I need this to be done in Oracle SQL (10gR2). But I guess, I would rather put it plainly, any good, efficient algorithm is fine.

Given a line (or sentence, containing

5条回答
  •  死守一世寂寞
    2020-12-19 14:41

    this leaves the punctuation but gets the final word

    with datam as (
    SELECT 'abc asdb.' A FROM DUAL UNION
    select 'ipso factum' a from dual union
    select 'ipso factum' a from dual union
    SELECT 'ipso factum2' A FROM DUAL UNION
    SELECT 'ipso factum!' A FROM DUAL UNION
    SELECT 'ipso factum  !' A FROM DUAL UNION
    SELECT 'ipso factum/**//*/?.?' A FROM DUAL UNION
    SELECT 'ipso factum  ...??!?!**' A FROM DUAL UNION
    select 'ipso factum ..d.../.>' a from dual 
    
    )
    SELECT a,
    --REGEXP_SUBSTR(A, '[[:alnum:]]_+$', 1, 1, 'c') , /** these are the other examples*/
    --REGEXP_SUBSTR(A, '\S+$') ,  /** these are the other examples*/
    regexp_substr(a, '[a-zA-Z]+[^a-zA-Z]*$')  
    
    from datam
    

提交回复
热议问题