限制特定长度来自特定文本

huangapple go评论69阅读模式
英文:

Limiting to specific length from a particular text

问题

Output:

Column A Column B
S101 Sentence 1: There once was a poor boy who spent hi Sentence 2: The poor boy asked for food but was de Sentence 3: Years later, the girl, who was now a g Sentence 4: The doctor spent months treating her u
S102 Sentence 1: There once was a king named Midas who Sentence 2: For his wish, Midas asked that whateve Sentence 3: Excited about his newly-earned powers,
英文:

Lets say I have a field of long text.

Column A Column B
S101 Sentence 1: There once was a poor boy who spent his days going door-to-door selling newspapers to pay for school. One day, as he was walking his route, he started feeling low and weak.The poor boy was starving, so he decided to ask for food when he came to the next door. Sentence 2: The poor boy asked for food but was denied every time, until he reached the door of a girl. He asked for a glass of water,but seeing his poor state, the girl came back with a glass of milk. The boy asked how much he owed her for the milk, but she refused payment.Sentence 3: Years later, the girl, who was now a grown woman, fell sick. She went from doctor to doctor, but no one was able to cure her.Finally, she went to the best doctor in town.Sentence 4: The doctor spent months treating her until she was finally cured. Despite her happiness, she was afraid she couldn’t afford to pay the bill. But, when the hospital handed her the bill, it read, ‘Paid in full, with a glass of milk.’
S102 Sentence 1: There once was a king named Midas who did a good deed for a Satyr. And he was then granted a wish by Dionysus, the god of wine. Sentence 2: For his wish, Midas asked that whatever he touched would turn to gold. Despite Dionysus’ efforts to prevent it, Midas pleaded that this was a fantastic wish, and so, it was bestowed. Sentence 3: Excited about his newly-earned powers, Midas started touching all kinds of things, turning each item into pure gold.

Every time the word "sentence" shows, we will trim the data from the word "sentence" to 50 characters.

Output:

Column A Column B
S101 Sentence 1: There once was a poor boy who spent hi Sentence 2: The poor boy asked for food but was de Sentence 3: Years later, the girl, who was now a g Sentence 4: The doctor spent months treating her u
S102 Sentence 1: There once was a king named Midas who Sentence 2: For his wish, Midas asked that whateve Sentence 3: Excited about his newly-earned powers,

I tried combination of substring and instring, but didn't work out

答案1

得分: 1

Here is the translated content:

如果你没有/不想/不知道正则表达式,你可以使用更快的旧函数 SubStr() 和 InStr() 来获得你期望的结果。
以样本数据为例:

WITH      --  样本    数据 :
	tbl (COL_A, COL_B) AS
		(	Select  'S101', 
              '	Sentence 1: There once was a poor boy who spent his days going door-to-door selling newspapers to pay for school. 
              One day, as he was walking his route, he started feeling low and weak.The poor boy was starving, so he decided 
              to ask for food when he came to the next door. 
              Sentence 2: The poor boy asked for food but was denied every time, 
              until he reached the door of a girl. He asked for a glass of water,but seeing his poor state, the girl came back 
              with a glass of milk. The boy asked how much he owed her for the milk, but she refused payment.
              Sentence 3: Years later, the girl, who was now a grown woman, fell sick. She went from doctor to doctor, but no one 
              was able to cure her.Finally, she went to the best doctor in town.
              Sentence 4: The doctor spent months treating her until she was finally cured. Despite her happiness, she was afraid 
              she couldn’t afford to pay the bill. But, when the hospital handed her the bill, it read, ‘Paid in full, with a glass of milk.’' 
      From Dual 
		)

子查询限制 LEVEL 连接计算 COL_B 中字符串 'Sentence ' 的出现次数。在代码中使用了 InStr() 函数。
选项 1:将每个缩短的句子都返回到自己的行中:

Select  COL_A,
        SubStr(COL_B, InStr(COL_B, 'Sentence ', 1, LEVEL), 50) "COL_B"
From    tbl
Connect By LEVEL <= ( Select (Length(COL_B) - Length(REPLACE(COL_B, 'Sentence ')) ) / Length('Sentence ') "SENTENCES" From tbl )

--  COL_A  COL_B                                             
--  -----  --------------------------------------------------
--  S101   Sentence 1: There once was a poor boy who spent hi
--  S101   Sentence 2: The poor boy asked for food but was de
--  S101   Sentence 3: Years later, the girl, who was now a g
--  S101   Sentence 4: The doctor spent months treating her u

选项 2:将所有缩短的句子都返回到 1 行中(要注意 VarChar2 数据类型的 4000 个字符限制):

Select  COL_A,
        LISTAGG(SubStr(COL_B, InStr(COL_B, 'Sentence ', 1, LEVEL), 50), Chr(10)) WITHIN GROUP (ORDER BY LEVEL) OVER(Partition By COL_A) "COL_B"
From    tbl
Connect By LEVEL <= ( Select (Length(COL_B) - Length(REPLACE(COL_B, 'Sentence ')) ) / Length('Sentence ') "SENTENCES" From tbl )
FETCH FIRST ROW ONLY
--  
--  结果:
--  COL_A  COL_B
--  -----  --------------------------------------------------
--  S101   Sentence 1: There once was a poor boy who spent hi 
--         Sentence 2: The poor boy asked for food but was de 
--         Sentence 3: Years later, the girl, who was now a g 
--         Sentence 4: The doctor spent months treating her u

注意:使用 Chr(10) 作为分隔符以使结果按行显示,你可以使用适合你的其他任何内容。
附加
对于多行,你应该通过表的关键列在 Connect By 子句中筛选子查询,然后要么使用 DISTINCT 关键字(在行数较多时可能会影响性能),要么在 COL_B 上进行 COL_A 分组的汇总(Max 或 Min)。这两种方法(Distinct 和 Aggregation)都将删除重复的行(在选项 2 中不需要 Fetch First)。以下是代码:

-- 选项 1
Select  DISTINCT t.COL_A,
        SubStr(t.COL_B, InStr(t.COL_B, 'Sentence ', 1, LEVEL), 50) "COL_B"
From    tbl t
Connect By LEVEL <= ( Select (Length(COL_B) - Length(REPLACE(COL_B, 'Sentence ')) ) / Length('Sentence ') "SENTENCES" From tbl Where COL_A = t.COL_A)        
Order By COL_A, COL_B        

-- 选项 2        
Select  DISTINCT t.COL_A,
        LISTAGG(SubStr(t.COL_B, InStr(t.COL_B, 'Sentence ', 1, LEVEL), 50), Chr(10)) WITHIN GROUP (ORDER BY LEVEL) OVER(Partition By t.COL_A) "COL_B"
From    tbl t
Connect By LEVEL <= ( Select (Length(COL_B) - Length(REPLACE(COL_B, 'Sentence ')) ) / Length('Sentence ') "SENTENCES" From tbl Where COL_A = t.COL_A)
Order By COL_A
英文:

If you don't have/want/know regexp you could use significantly faster old functions SubStr() And InStr() to get your expected result.
With sample data as:

WITH      --  S a m p l e    D a t a :
	tbl (COL_A, COL_B) AS
		(	Select  &#39;S101&#39;, 
              &#39;	Sentence 1: There once was a poor boy who spent his days going door-to-door selling newspapers to pay for school. 
              One day, as he was walking his route, he started feeling low and weak.The poor boy was starving, so he decided 
              to ask for food when he came to the next door. 
              Sentence 2: The poor boy asked for food but was denied every time, 
              until he reached the door of a girl. He asked for a glass of water,but seeing his poor state, the girl came back 
              with a glass of milk. The boy asked how much he owed her for the milk, but she refused payment.
              Sentence 3: Years later, the girl, who was now a grown woman, fell sick. She went from doctor to doctor, but no one 
              was able to cure her.Finally, she went to the best doctor in town.
              Sentence 4: The doctor spent months treating her until she was finally cured. Despite her happiness, she was afraid 
              she couldnt afford to pay the bill. But, when the hospital handed her the bill, it read, Paid in full, with a glass of milk.&#39;
      From Dual 
		)

Subquery limiting LEVEL connections calculates number of occurencies of string 'Sentence ' in COL_B. Used in code with InStr() function.
Option 1: Return each shortened sntence in it's own row:

Select  COL_A,
        SubStr(COL_B, InStr(COL_B, &#39;Sentence &#39;, 1, LEVEL), 50) &quot;COL_B&quot;
From    tbl
Connect By LEVEL &lt;= ( Select (Length(COL_B) - Length(REPLACE(COL_B, &#39;Sentence &#39;)) ) / Length(&#39;Sentence &#39;) &quot;SENTENCES&quot; From tbl )

--  COL_A  COL_B                                             
--  -----  --------------------------------------------------
--  S101   Sentence 1: There once was a poor boy who spent hi
--  S101   Sentence 2: The poor boy asked for food but was de
--  S101   Sentence 3: Years later, the girl, who was now a g
--  S101   Sentence 4: The doctor spent months treating her u

Option 2: Return all shortened sentences in 1 row (be aware of 4000 chars limit for VarChar2 datatype):

Select  COL_A,
        LISTAGG(SubStr(COL_B, InStr(COL_B, &#39;Sentence &#39;, 1, LEVEL), 50), Chr(10)) WITHIN GROUP (ORDER BY LEVEL) OVER(Partition By COL_A) &quot;COL_B&quot;
From    tbl
Connect By LEVEL &lt;= ( Select (Length(COL_B) - Length(REPLACE(COL_B, &#39;Sentence &#39;)) ) / Length(&#39;Sentence &#39;) &quot;SENTENCES&quot; From tbl )
FETCH FIRST ROW ONLY
--  
--  R e s u l t:
--  COL_A  COL_B
--  -----  --------------------------------------------------
--  S101   Sentence 1: There once was a poor boy who spent hi 
--         Sentence 2: The poor boy asked for food but was de 
--         Sentence 3: Years later, the girl, who was now a g 
--         Sentence 4: The doctor spent months treating her u

Note: Used Chr(10) as separator to get result in lines for better readability, you could use anything else that suits you.
ADDITION:
For multi rows you should filter the subquery in Connect By clause by key column of the table and either use DISTINCT keyword (could be performance costly with large number of rows) or do the aggregation on COL_B (Max or Min) grouped by COL_A. Both (Distinct and Aggregation) will remove duplicate rows (you don't need Fetch First in Option 2). Here is the code:

-- Option 1
Select  DISTINCT t.COL_A,
        SubStr(t.COL_B, InStr(t.COL_B, &#39;Sentence &#39;, 1, LEVEL), 50) &quot;COL_B&quot;
From    tbl t
Connect By LEVEL &lt;= ( Select (Length(COL_B) - Length(REPLACE(COL_B, &#39;Sentence &#39;)) ) / Length(&#39;Sentence &#39;) &quot;SENTENCES&quot; From tbl Where COL_A = t.COL_A)        
Order By COL_A, COL_B        
      
-- Option 2        
Select  DISTINCT t.COL_A,
        LISTAGG(SubStr(t.COL_B, InStr(t.COL_B, &#39;Sentence &#39;, 1, LEVEL), 50), Chr(10)) WITHIN GROUP (ORDER BY LEVEL) OVER(Partition By t.COL_A) &quot;COL_B&quot;
From    tbl t
Connect By LEVEL &lt;= ( Select (Length(COL_B) - Length(REPLACE(COL_B, &#39;Sentence &#39;)) ) / Length(&#39;Sentence &#39;) &quot;SENTENCES&quot; From tbl Where COL_A = t.COL_A)
Order By COL_A

答案2

得分: 0

一个选择可能是将这段文本分成行(每行一个句子),从每行中提取50个字符,然后将它们聚合在一起。

示例数据:

SQL&gt; with test (col) as
  2  (select 'Sentence 1: There once was a poor boy who spent his days going door-to-door selling
  3  newspapers to pay for school. One day, as he was walking his route, he started feeling low and weak.
  4  The poor boy was starving, so he decided to ask for food when he came to the next door.
  5  Sentence 2: The poor boy asked for food but was denied every time, until he reached the door of a girl.
  6  He asked for a glass of water, but seeing his poor state, the girl came back with a glass of milk.
  7  The boy asked how much he owed her for the milk, but she refused payment.
  8  Sentence 3: Years later, the girl, who was now a grown woman, fell sick. She went from doctor
  9  to doctor, but no one was able to cure her. Finally, she went to the best doctor in town.
  10  Sentence 4: The doctor spent months treating her until she was finally cured. Despite her
  11  happiness, she was afraid she couldn’t afford to pay the bill. But, when the hospital
  12  handed her the bill, it read, ‘Paid in full, with a glass of milk.' from dual),

查询开始于此:

  13  temp as
  14    (select level lvl,
  15            regexp_substr(replace(col, 'Sentence', '#'), '[^#]+', 1, level) val
  16     From test
  17     connect by level &lt;= regexp_count(col, 'Sentence')
  18    )
  19  select listagg(substr('Sentence ' || val, 1, 51), ' ') within group (order by lvl) result
  20  from temp;

结果如下:

RESULT
--------------------------------------------------------------------------------
Sentence 1: There once was a poor boy who spent hi Sentence 2: The poor boy as
ked for food but was de Sentence 3: Years later, the girl, who was now a g Sent
ence 4: The doctor spent months treating her u

注意:这是查询的翻译部分。

英文:

One option might be to split that long text into rows (one row per sentence), extract 50 characters from each row and aggregate them back.

Sample data:

SQL&gt; with test (col) as
  2  (select &#39;Sentence 1: There once was a poor boy who spent his days going door-to-door selling
  3  newspapers to pay for school. One day, as he was walking his route, he started feeling low and weak.
  4  The poor boy was starving, so he decided to ask for food when he came to the next door.
  5  Sentence 2: The poor boy asked for food but was denied every time, until he reached the door of a girl.
  6  He asked for a glass of water,but seeing his poor state, the girl came back with a glass of milk.
  7  The boy asked how much he owed her for the milk, but she refused payment.
  8  Sentence 3: Years later, the girl, who was now a grown woman, fell sick. She went from doctor
  9  to doctor, but no one was able to cure her.Finally, she went to the best doctor in town.
 10  Sentence 4: The doctor spent months treating her until she was finally cured. Despite her
 11  happiness, she was afraid she couldn’t afford to pay the bill. But, when the hospital
 12  handed her the bill, it read, ‘Paid in full, with a glass of milk.&#39; from dual),

Query begins here:

 13  temp as
 14    (select level lvl,
 15            regexp_substr(replace(col, &#39;Sentence&#39;, &#39;#&#39;), &#39;[^#]+&#39;, 1, level) val
 16     From test
 17     connect by level &lt;= regexp_count(col, &#39;Sentence&#39;)
 18    )
 19  select listagg(substr(&#39;Sentence &#39; || val, 1, 51), &#39; &#39;) within group (order by lvl) result
 20  from temp;

RESULT
--------------------------------------------------------------------------------
Sentence  1: There once was a poor boy who spent hi Sentence  2: The poor boy as
ked for food but was de Sentence  3: Years later, the girl, who was now a g Sent
ence  4: The doctor spent months treating her u


SQL&gt;

答案3

得分: 0

select
  REGEXP_REPLACE(
    '句子 1:曾经有一个贫穷的男孩,他白天挨家挨户卖报纸来支付学费。一天,当他走着他的路线时,他开始感到虚弱和无力。这个贫穷的男孩饿坏了,所以他决定在下一个门口要点食物。句子 2:这个贫穷的男孩要了吃的,但每次都被拒绝,直到他来到一个女孩的门口。他要了一杯水,但看到他的贫困状况,女孩拿了一杯牛奶给他。男孩问她为牛奶应该付多少钱,但她拒绝了付款。句子 3:多年后,这个女孩,现在已经长大成为一个女人,生病了。她去找医生,但没有人能够治好她。最后,她去找了镇上最好的医生。句子 4:医生花了几个月的时间治疗她,直到她最终痊愈。尽管她很高兴,但她担心自己负担不起账单。但当医院递给她账单时,上面写着:“已付清,附带一杯牛奶。”',
    '(: )(.{1,38})(.*?)(句子\s+\d+|$)',
    ' '
  ) from dual
英文:

I thought using a regexp without lookahead or lookbehind (as it is not supported):

select
  REGEXP_REPLACE(
    &#39;Sentence 1: There once was a poor boy who spent his days going door-to-door selling newspapers to pay for school. One day, as he was walking his route, he started feeling low and weak.The poor boy was starving, so he decided to ask for food when he came to the next door. Sentence 2: The poor boy asked for food but was denied every time, until he reached the door of a girl. He asked for a glass of water,but seeing his poor state, the girl came back with a glass of milk. The boy asked how much he owed her for the milk, but she refused payment.Sentence 3: Years later, the girl, who was now a grown woman, fell sick. She went from doctor to doctor, but no one was able to cure her.Finally, she went to the best doctor in town.Sentence 4: The doctor spent months treating her until she was finally cured. Despite her happiness, she was afraid she couldnt afford to pay the bill. But, when the hospital handed her the bill, it read, Paid in full, with a glass of milk.&#39;,
    &#39;(: )(.{1,38})(.*?)(Sentence\s+\d+|$)&#39;,
    &#39;\1\2 \4&#39;
  ) from dual

The idea was that we know that it starts with Sentence followed by a number
and then : so we could assume that we first start by searching : and then capture what is before the next Sentense # (where # is some digits).

We capture the text in the second group with a security in case it is shorter than expected. Then we capture the text to remove and then match the next sentence delimiter.

You can test it here: https://dbfiddle.uk/kGQMyNx_

答案4

得分: 0

@Littlefoot的答案大部分有效,但依赖于将&#39;Sentence&#39;替换为&#39;#&#39;以使正则表达式&#39;[^#]+&#39;工作,这意味着当输入包含&#39;#&#39;本身时会失败。

更稳健的方法是改用instr函数来查找输入中&#39;Sentence&#39;出现的位置:

with sentences as (
    select
        &#39;Sentence 1: There once was a poor boy who spent his days going door-to-door selling newspapers to pay for school. One day, as he was walking his route, he started feeling low and weak. The poor boy was starving, so he decided to ask for food when he came to the next door. Sentence 2: The poor boy asked for food but was denied every time, until he reached the door of a girl. He asked for a glass of water, but seeing his poor state, the girl came back with a glass of milk. The boy asked how much he owed her for the milk, but she refused payment. Sentence 3: Years later, the girl, who was now a grown woman, fell sick. She went from doctor to doctor, but no one was able to cure her. Finally, she went to the best doctor in town. Sentence 4: The doctor spent months treating her until she was finally cured. Despite her happiness, she was afraid she couldnt afford to pay the bill. But, when the hospital handed her the bill, it read, Paid in full, with a glass of milk.&#39;
        as s from dual
)
select listagg(sentence, &#39; &#39;) within group (order by lvl)
from (
    select substr(s, instr(s, &#39;Sentence&#39;, 1, level), 50) sentence, level lvl
    from sentences
    connect by level &lt;= regexp_count(s, &#39;Sentence&#39;)
);

这会输出:

Sentence 1: There once was a poor boy who spent hi Sentence 2: The poor boy asked for food but was de Sentence 3: Years later, the girl, who was now a g Sentence 4: The doctor spent months treating her u

演示链接:https://livesql.oracle.com/apex/livesql/s/o8l4vu3rzs67vs8ag2ldmzs6k

英文:

@Littlefoot's answer mostly works but relies on replacing &#39;Sentence&#39; with &#39;#&#39; to make the regex &#39;[^#]+&#39; work, which means it would fail when the input contains &#39;#&#39; itself.

A more robust approach would be to use the instr function instead to find the positions of occurrences of &#39;Sentence&#39; in the input:

with sentences as (
    select
    	&#39;Sentence 1: There once was a poor boy who spent his days going door-to-door selling newspapers to pay for school. One day, as he was walking his route, he started feeling low and weak.The poor boy was starving, so he decided to ask for food when he came to the next door. Sentence 2: The poor boy asked for food but was denied every time, until he reached the door of a girl. He asked for a glass of water,but seeing his poor state, the girl came back with a glass of milk. The boy asked how much he owed her for the milk, but she refused payment.Sentence 3: Years later, the girl, who was now a grown woman, fell sick. She went from doctor to doctor, but no one was able to cure her.Finally, she went to the best doctor in town.Sentence 4: The doctor spent months treating her until she was finally cured. Despite her happiness, she was afraid she couldn’t afford to pay the bill. But, when the hospital handed her the bill, it read, ‘Paid in full, with a glass of milk.’&#39;
    	as s from dual
)
select listagg(sentence, &#39; &#39;) within group (order by lvl)
from (
    select substr(s, instr(s, &#39;Sentence&#39;, 1, level), 50) sentence, level lvl
    from sentences
	connect by level &lt;= regexp_count(s, &#39;Sentence&#39;)
);

This outputs:

Sentence 1: There once was a poor boy who spent hi Sentence 2: The poor boy asked for food but was de Sentence 3: Years later, the girl, who was now a g Sentence 4: The doctor spent months treating her u

Demo: https://livesql.oracle.com/apex/livesql/s/o8l4vu3rzs67vs8ag2ldmzs6k

答案5

得分: 0

您可以使用递归查询来查找以Sentence \d+:开头的每个子字符串,并递归连接这些子字符串的最多50个字符:

WITH data (rn, column_a, column_b, epos, updated_column_b) AS (
  SELECT ROWNUM,
         column_a,
         column_b,
         1,
         EMPTY_CLOB()
  FROM   table_name
UNION ALL
  SELECT rn,
         column_a,
         column_b,
         REGEXP_INSTR(column_b, &#39;Sentence \d+:&#39;, epos, 2),
         updated_column_b
         || &#39; &#39;
         || SUBSTR(
              column_b,
              epos,
              CASE REGEXP_INSTR(column_b, &#39;Sentence \d+:&#39;, epos, 2)
              WHEN 0
              THEN 50
              ELSE LEAST(
                     50,
                     REGEXP_INSTR(column_b, &#39;Sentence \d+:&#39;, epos, 2) - epos
                   )
              END
            )
  FROM   data
  WHERE  epos &gt; 0
)
SEARCH DEPTH FIRST BY rn SET order_id
SELECT column_a,
       SUBSTR(updated_column_b, 2) AS updated_column_b
FROM   data
WHERE  epos = 0;

对于示例数据:

CREATE TABLE table_name (Column_A, Column_B) AS
SELECT &#39;S101&#39;,
       EMPTY_CLOB() || &#39;Sentence 1: There once was a poor boy who spent his days going door-to-door selling newspapers to pay for school. One day, as he was walking his route, he started feeling low and weak.The poor boy was starving, so he decided to ask for food when he came to the next door. Sentence 2: The poor boy asked for food but was denied every time, until he reached the door of a girl. He asked for a glass of water,but seeing his poor state, the girl came back with a glass of milk. The boy asked how much he owed her for the milk, but she refused payment.Sentence 3: Years later, the girl, who was now a grown woman, fell sick. She went from doctor to doctor, but no one was able to cure her.Finally, she went to the best doctor in town.Sentence 4: The doctor spent months treating her until she was finally cured. Despite her happiness, she was afraid she couldn’t afford to pay the bill. But, when the hospital handed her the bill, it read, ‘Paid in full, with a glass of milk.’&#39;
FROM   DUAL

输出为:

COLUMN_A UPDATED_COLUMN_B
S101 Sentence 1: There once was a poor boy who spent hi Sentence 2: The poor boy asked for food but was de Sentence 3: Years later, the girl, who was now a g Sentence 4: The doctor spent months treating her u

fiddle

英文:

You can use a recursive query to find each sub-string starting with Sentence \d+: and recursively concatenate up to 50 characters of those sub-strings:

WITH data (rn, column_a, column_b, epos, updated_column_b) AS (
  SELECT ROWNUM,
         column_a,
         column_b,
         1,
         EMPTY_CLOB()
  FROM   table_name
UNION ALL
  SELECT rn,
         column_a,
         column_b,
         REGEXP_INSTR(column_b, &#39;Sentence \d+:&#39;, epos, 2),
         updated_column_b
         || &#39; &#39;
         || SUBSTR(
              column_b,
              epos,
              CASE REGEXP_INSTR(column_b, &#39;Sentence \d+:&#39;, epos, 2)
              WHEN 0
              THEN 50
              ELSE LEAST(
                     50,
                     REGEXP_INSTR(column_b, &#39;Sentence \d+:&#39;, epos, 2) - epos
                   )
              END
            )
  FROM   data
  WHERE  epos &gt; 0
)
SEARCH DEPTH FIRST BY rn SET order_id
SELECT column_a,
       SUBSTR(updated_column_b, 2) AS updated_column_b
FROM   data
WHERE  epos = 0;

Which, for the sample data:

CREATE TABLE table_name (Column_A, Column_B) AS
SELECT &#39;S101&#39;,
       EMPTY_CLOB() || &#39;Sentence 1: There once was a poor boy who spent his days going door-to-door selling newspapers to pay for school. One day, as he was walking his route, he started feeling low and weak.The poor boy was starving, so he decided to ask for food when he came to the next door. Sentence 2: The poor boy asked for food but was denied every time, until he reached the door of a girl. He asked for a glass of water,but seeing his poor state, the girl came back with a glass of milk. The boy asked how much he owed her for the milk, but she refused payment.Sentence 3: Years later, the girl, who was now a grown woman, fell sick. She went from doctor to doctor, but no one was able to cure her.Finally, she went to the best doctor in town.Sentence 4: The doctor spent months treating her until she was finally cured. Despite her happiness, she was afraid she couldn’t afford to pay the bill. But, when the hospital handed her the bill, it read, ‘Paid in full, with a glass of milk.’&#39;
FROM   DUAL

Which outputs:

COLUMN_A UPDATED_COLUMN_B
S101 Sentence 1: There once was a poor boy who spent hi Sentence 2: The poor boy asked for food but was de Sentence 3: Years later, the girl, who was now a g Sentence 4: The doctor spent months treating her u

fiddle

答案6

得分: -1

这是一个可以匹配每个长度不超过50个字符的句子的正则表达式:

Sentence.{50}

希望对您有所帮助。

英文:

Here is a regex that catches every "sentence up to 50 characters":

Sentence.{50}

I hope it will help.

huangapple
  • 本文由 发表于 2023年5月26日 14:41:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76338234.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定