行的正则表达式分隔了多个冗长的单词 [英] regular expression for line seperated different lengthy words

查看:114
本文介绍了行的正则表达式分隔了多个冗长的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从另一篇帖子中得到了以下查询,但似乎不适用于单个字符.

I've got the below query from another post but seems its not working for single character.

SELECT regexp_substr('abc
def
ghi', '.+[[:alpha:]]', 1 ,level)
FROM dual
     CONNECT BY regexp_substr('abc
def
ghi', '.+[[:alpha:]]', 1 ,level) IS NOT NULL;

输出

abc
def
ghi

当我为单个字符尝试此操作时,它无法按预期工作.

When I try this for a single character it doesn't work as expected.

 SELECT regexp_substr('a
b
c', '.+[[:alpha:]]', 1 ,level)
FROM dual
     CONNECT BY regexp_substr('a
b
c', '.+[[:alpha:]]', 1 ,level) IS NOT NULL;

推荐答案

这是因为您使用了正则表达式.对其进行更改以查找 just 个连续的字母字符:

It's because of your regular expression. Change it to look for just consecutive alphabetic characters:

 select regexp_substr('abc
 def
 ghi', '[[:alpha:]]+', 1 ,level)
   from dual
connect by regexp_substr('abc
def
ghi', '[[:alpha:]]+', 1 ,level) is not null

它也适用于单个字符:

select regexp_substr('a
b
c', '[[:alpha:]]+', 1 ,level)
from dual
     connect by regexp_substr('a
b
c', '[[:alpha:]]+', 1 ,level) is not null;

您已评论:

但是我的实际要求是,单行可能有也可能没有单个单词或单个字符,其中也包含数字,空格等,例如:'这是一个数字333

but my actual requirement is that , the single line may or maynot have single word, or a single character, which also contains numbers , spaces etc ., for example: 'this is a number333

请始终在问题中输入所有信息.

Please always put all the information in the question to begin with please.

您似乎希望拆分换行符(回车符或回车符/换行符)

You seem to be looking to split on a newline character (carriage return or carriage return/line feed)

在这种情况下,您要分割的字符不是这些字符之一.我在这里使用了所有控制字符,因为我很懒,但是它将适用于您提供的数据.如果您有一些贝尔字符,这将无法正常工作,则必须更加具体.

In which case you're looking to split where something is not one of these characters. I've used all control characters here because I'm lazy but it will work for your provided data. If you have some Bell characters this won't work, you'll have to be more specific.

with the_data as ( 
select 'a
b
c' as dat
  from dual
       )
 select regexp_substr(dat, '[^[:cntrl:]]+', 1 ,level)
  from the_data
connect by regexp_substr(dat, '[^[:cntrl:]]+', 1 ,level) is not null;

这篇关于行的正则表达式分隔了多个冗长的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆