正则表达式

delectation 2008-01-29 09:47:17
表中有一列,形式如下

qq-001-100
qq-001-100R
bb-123-234
bb-256-100R0
bb-256-100R1
...
bb-256-100R9

cc-678-123B
....

在查询时排除以R,B,R0~R9结尾的数据.我写了一个[^RB],可是不能排除以R0~R9这样结尾的.

...全文
118 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
-狙击手- 2008-01-29
  • 打赏
  • 举报
回复
declare @s table(col varchar(100))
insert @s
select
'qq-001-100' union select
'qq-001-100R' union select
'bb-123-234' union select
'bb-256-100R0' union select
'bb-256-100R1' union select
'bb-256-100R9' union select
'cc-678-123B'



select *
from @s
where not (PATINDEX( '%[RB]',col) > 0 or PATINDEX( '%[R][0-9]',col) > 0)
pt1314917 2008-01-29
  • 打赏
  • 举报
回复

declare @t table(val varchar(50))
insert into @t select 'qq-001-100'
insert into @t select 'qq-001-100R'
insert into @t select 'bb-123-234'
insert into @t select 'bb-256-100R0'
insert into @t select 'bb-256-100R1'
insert into @t select 'bb-256-100R9'
insert into @t select 'cc-678-123B'

select * from @t where
patindex('%[^RB]',val)>0
and
patindex('%R[0-9]',val)=0
popeye627 2008-01-29
  • 打赏
  • 举报
回复

select * from
(
select 'qq-001-100' as a union
select 'qq-001-100R' union
select 'bb-123-234' union
select 'bb-256-100R0' union
select 'bb-256-100RT1' union
select 'bb-256-100R9' union
select 'cc-678-123B' union
select 'bb-256-100B3' union
select 'bb-256-100R4' union
select 'bb-256-100R6'
) t
where right(a,1) not in ('R','B')
and a not like '%_R[0-9]'

-------------------------------
a
-------------
bb-123-234
bb-256-100B3
bb-256-100RT1
qq-001-100

(4 個資料列受到影響)
pt1314917 2008-01-29
  • 打赏
  • 举报
回复
select * from @t where 
patindex('%[^RB]',val)>0
and
patindex('%[^R0]',val)>0
and
patindex('%[^R9]',val)>0
fcuandy 2008-01-29
  • 打赏
  • 举报
回复
其实我写的这个有条件限制的.

排除 你的数据中有 rx,rz,rv,ra 结尾的这样的数据的可能.

也即你如果以 r? 结尾只有 r0--r9 这样是可以的.
delectation 2008-01-29
  • 打赏
  • 举报
回复
to fcuandy
请解释一下.谢谢
fcuandy 2008-01-29
  • 打赏
  • 举报
回复
再次声明,这不是正则,这是简单的通配符

declare @t table(val varchar(50))
insert into @t select 'qq-001-100'
insert into @t select 'qq-001-100R'
insert into @t select 'bb-123-234'
insert into @t select 'bb-256-100R0'
insert into @t select 'bb-256-100R1'
insert into @t select 'bb-256-100R9'
insert into @t select 'cc-678-123B'

select * from @t where val like '%[^r][^rb]'
JL99000 2008-01-29
  • 打赏
  • 举报
回复
if object_id('tb') is not null
drop table tb
go
create table tb(mm varchar(100))
insert tb
select 'qq-001-100' union all
select 'qq-001-100R' union all
select 'bb-123-234' union all
select 'bb-256-100R0' union all
select 'bb-256-100R1' union all
select 'bb-256-100R9' union all
select 'cc-678-123B'

select * from tb
where right(mm,1)<>'R' and right(mm,1)<>'B' and right(mm,2) not like '%R[0-9]'

接分
【更新至2025年】2001-2025年上市公司数字化转型年报词频统计(吴非、赵宸宇、甄红线)(300+年报词频统计) 1、时间:2001-2025年 2、来源:上市公司年报 3、参考文献:企业数字化转型与资本市场表现——来自股票流动性的经验证据(吴非) 数字化转型如何影响企业全要素生产率(赵宸宇) 知识产权行政保护与企业数字化转型(甄红线) 4、方法说明:(1)参考吴非老师的做法,对人工智能技术、大数据技术、云计算技术、区块链技术、数字技术运用五个维度76个数字化相关词频进行统计 (2)参考赵宸宇老师的做法,对数字技术应用、互联网商业模式、智能制造、现代信息系统四个维度99个数字化相关词频进行统计 (3)参考甄红线老师的做法,对技术分类、组织赋能、数字化应用等类别下139个数字化相关词频进行统计 5、指标:年份、股票代码、公司简称、行业名称、行业代码、全文-文本总长度、仅中英文-文本总长度、人工智能技术-吴、大数据技术-吴、云计算技术-吴、区块链技术-吴、数字技术运用-吴、数字技术应用-赵、互联网商业模式-赵、智能制造-赵、现代信息系统-赵、技术分类-人工智能技术-甄、技术分类-区块链技术-甄、技术分类-云计算技术-甄、技术分类-大数据技术-甄、组织赋能-人工智能技术-甄、组织赋能-云计算技术-甄、组织赋能-大数据技术-甄、组织赋能-广义数字技术-甄、数字化应用-技术创新-甄、数字化应用-流程创新-甄、数字化应用-业务创新-甄、人工智能、商业智能、图像理解、投资决策辅助系统、智能数据分析、智能机器人、机器学习、深度学习、语义搜索、生物识别技术、人脸识别、语音识别、身份验证、自动驾驶、自然语言处理、大数据、数据挖掘、文本挖掘、数据可视化、异构数据、征信、增强现实、混合现实、虚拟现实、云计算、流计算、图计算、内存计算、多方安全计算、类脑计算、绿色计算、认知计算等300+词频

34,876

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧