这里是我的散列:提取最后一个实例
---
0:
id: 11259
year: 1997
status: other
priority:
created_at: !ruby/object:ActiveSupport::TimeWithZone
utc: 2017-01-13 15:02:22.000000000 Z
zone: !ruby/object:ActiveSupport::TimeZone
name: Etc/UTC
time: 2017-01-13 15:02:22.000000000 Z
updated_at: !ruby/object:ActiveSupport::TimeWithZone
utc: 2017-01-13 15:02:22.000000000 Z
zone: !ruby/object:ActiveSupport::TimeZone
name: Etc/UTC
time: 2017-01-13 15:02:22.000000000 Z
1:
id: 82829
year: 1931
status: won
priority:
created_at: !ruby/object:ActiveSupport::TimeWithZone
utc: 2017-01-13 15:02:22.000000000 Z
zone: !ruby/object:ActiveSupport::TimeZone
name: Etc/UTC
time: 2017-01-13 15:02:22.000000000 Z
updated_at: !ruby/object:ActiveSupport::TimeWithZone
utc: 2017-01-13 15:02:22.000000000 Z
zone: !ruby/object:ActiveSupport::TimeZone
name: Etc/UTC
time: 2017-01-13 15:02:22.000000000 Z
我希望做两件事情之一:
(1)提取两个“身份证的
id: 11259
id: 82829
( 2)仅提取最终'id':
id: 82829
到目前为止,我只能够提取第一 ID:
REGEXP_SUBSTR(hash_name, "id: .*?\n")
感谢。
您确定您使用的是MySQL吗?它没有'REGEXP_SUBSTR()'函数。该功能仅存在于Oracle和MariaDB中。 – Barmar
MariaDB使用PCRE,因此您可以使用负面预测来查找字符串后面没有另一个“id:”后面的'id:'。然后它会匹配字符串中的最后一个'id:'。 – Barmar