0

对于这些字符串

   RSLR_AIRL19_ID3454_T20030913091226
   RSLR_AIRL19_ID3122454_T20030913091226
   RSLR_AIRL19_ID34_T20030913091226

ID后面的号码怎么获取?

或者如何获取两个字符之间的内容但不包含它们?

我用这个'/\_ID([^_]+)/'得到了像数组这样的匹配( [0] => _ID3454 [1] => 3454 )

这是正确的方法吗?

4

2 回答 2

0

使用引擎:

ID\K\w+

笔记

\K“重新开始”比赛。

http://www.phpfreaks.com/blog/pcre-regex-spotlight-kphp使用pcre

于 2012-11-15T00:42:47.637 回答
0

要在 之后提取数字ID,您可以编写类似的查询。

SQL> with t1 as(
  2    select 'RSLR_AIRL19_ID3454_T20030913091226' as col from dual union all
  3    select 'RSLR_AIRL19_ID3122454_T20030913091226'     from dual union all
  4    select 'RSLR_AIRL19_ID34_T20030913091226'          from dual
  5  )
  6  select regexp_substr(col, '^([[:alnum:]]+_){2}ID([[:digit:]]+)_([[:alnum:]]+){1}$', 1, 1, 'i', 2) as ID
  7    from t1
  8  ;

ID
-------------
3454
3122454
34

或者,如果您想从第一次出现的模式中提取数字而不验证整个字符串是否与特定格式匹配:

SQL> with t1 as(
  2    select 'RSLR_AI_RL19_ID3454_T20030913091226' as col from dual union all
  3    select 'RSLR_AIRL19_ID3122454_T20030913091226'      from dual union all
  4    select 'RSLR_AIRL19_ID34_T20030913091226'           from dual
  5  )
  6  select regexp_substr(col, 'ID([[:digit:]]+)', 1, 1, 'i', 1) as ID
  7    from t1
  8  ;

ID
--------------
3454
3122454
34 
于 2012-11-24T08:52:22.573 回答