0

我有 REGEXP 表达式,需要接受特定字母的开头,特定结尾字母之间的任何内容,并且该结尾字母之后可能有空格。(来自数据库)当我运行我的表达式时,它没有给我结束字母,因为它在我正在搜索的名称后面有数据库中的空格

 WHERE REGEXP_LIKE (cname, UPPER('^[&p_name_beginning](.*?)[&p_name_ending$]'));

输出:

JIE DONG has bought 2 car(s) and has spent $151200
JAMES BARREDO has bought 1 car(s) and has spent $300145
JUAN MENDIOLA has bought 1 car(s) and has spent $75610.89
JASON HADDAD has bought 1 car(s) and has spent $157000
JOSE ANDRADE has bought 1 car(s) and has spent $151046
JORDAN PENNEY has bought 1 car(s) and has spent $85201.92
JUAN RODAS has bought 1 car(s) and has spent $105000
4

1 回答 1

0

如果您在数据前后指定您尝试对样本执行的操作,并显示您尝试过的内容,您将获得更好的帮助。我怀疑您正在尝试选择名称的第一个和最后一个字母与您给出的参数匹配的行。如果您更新标签以显示您正在使用的数据库,您将获得更有针对性的答案,但我这里是一个 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' 表示不区分大小写。

于 2018-07-31T18:36:50.767 回答