如果您在数据前后指定您尝试对样本执行的操作,并显示您尝试过的内容,您将获得更好的帮助。我怀疑您正在尝试选择名称的第一个和最后一个字母与您给出的参数匹配的行。如果您更新标签以显示您正在使用的数据库,您将获得更有针对性的答案,但我这里是一个 Oracle 解决方案,用于返回第三条记录,如果我的假设正确,它可能会有所帮助。无论如何,它都会给你一个提示。
with tbl(str) as (
select 'JIE DONG has bought 2 car(s) and has spent $151200' from dual union all
select 'JAMES BARREDO has bought 1 car(s) and has spent $300145' from dual union all
select 'JUAN MENDIOLA has bought 1 car(s) and has spent $75610.89' from dual union all
select 'JASON HADDAD has bought 1 car(s) and has spent $157000' from dual union all
select 'JOSE ANDRADE has bought 1 car(s) and has spent $151046' from dual union all
select 'JORDAN PENNEY has bought 1 car(s) and has spent $85201.92' from dual union all
select 'JUAN RODAS has bought 1 car(s) and has spent $105000' from dual
)
select str
from tbl
where regexp_like(str, '^j\S+ \S+a .*$', 'i');
正则表达式如下:
^ Anchor to the start of the line
j Match a 'j' (first letter of name)
\S+ Followed by one or more characters that are not spaces
<space> Then a space character
\S+ Followed by one or more characters that are not spaces
a Then the ending letter of the name
<space> Followed by a space character
.* Followed by zero or more of any characters
$ The end of the line
'i' 表示不区分大小写。