使用ampscript在第n个定界线后从字符串中提取文本

发布于 2025-02-12 19:27:50 字数 344 浏览 0 评论 0原文

我需要能够在第n个定界符之后从字符串中提取。 在这种情况下,定界符是 下划线

挑战在于,最后一个定界符可以在第二,第三,第四或第五位置

示例

  1. lb_ab_ab_bookingReminder_123-1-1-1S(第三位置)

    >
  2. lb_ab_booking_reminder_reminder_123-1-2-1s(第4位)

所需的输出:123-1-2-1S

谢谢

I need to be able to extract from a string after nth delimiter.
In this case, the delimiter is an underscore.

The challenge is that the last delimiter could be in the 2nd, 3rd,4th or 5th position

Example:

  1. LB_AB_BookingReminder_123-1-2-1S (3rd position)

  2. LB_AB_123-1-2-1S (2nd position)

  3. LB_AB_Booking_Reminder_123-1-2-1S (4th position)

Output Needed: 123-1-2-1S

Thank You

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

涫野音 2025-02-19 19:27:50

Using the RegExMatch() function may be your best bet:

%%[

set @pattern = "^.+_(.+\-\d+\-\d+\-.+)"
set @s1 = "LB_AB_BookingReminder_123-1-2-1S"
set @s2 = "LB_AB_BookingReminder_123-1-2-1S"
set @s3 = "LB_AB_Booking_Reminder_123-1-2-1S"

set @match1 = RegExMatch(@s1, @pattern, 1)
set @match2 = RegExMatch(@s2, @pattern, 1)
set @match3 = RegExMatch(@s3, @pattern, 1)

]%%
<br>%%=v(@match1)=%%
<br>%%=v(@match2)=%%
<br>%%=v(@match3)=%%

Output:

123-1-2-1S
123-1-2-1S
123-1-2-1S

Regex101 snippet:

ampscript tester: https://mcsnippets.herokuapp.com/s/f4wisqvc

Using the RegExMatch() function may be your best bet:

%%[

set @pattern = "^.+_(.+\-\d+\-\d+\-.+)"
set @s1 = "LB_AB_BookingReminder_123-1-2-1S"
set @s2 = "LB_AB_BookingReminder_123-1-2-1S"
set @s3 = "LB_AB_Booking_Reminder_123-1-2-1S"

set @match1 = RegExMatch(@s1, @pattern, 1)
set @match2 = RegExMatch(@s2, @pattern, 1)
set @match3 = RegExMatch(@s3, @pattern, 1)

]%%
<br>%%=v(@match1)=%%
<br>%%=v(@match2)=%%
<br>%%=v(@match3)=%%

Output:

123-1-2-1S
123-1-2-1S
123-1-2-1S

Regex101 snippet: https://regex101.com/r/DJeKjd/1

AMPscript tester: https://mcsnippets.herokuapp.com/s/F4WISQvc

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文