Reputation: 21
What regex
would I need to get <t:1583277337:R>
to then replace it so it display the proper information (in this case: 3 Years ago
)
Why?
I'm trying to use it on Discord where Discord automatically converts <t:1583277337:R>
to the corresponding data, but the API retrieved data (below) doesnt automatically convert on Discord Embeds
Data
"bio": "𝖓𝖔𝖙 𝖊𝖛𝖊𝖗𝖞𝖔𝖓𝖊 𝖜𝖎𝖑𝖑 𝖇𝖊𝖑𝖎𝖊𝖛𝖊 𝖎𝖓 𝖞𝖔𝖚, 𝖇𝖚𝖙 𝖓𝖔𝖙 𝖊𝖛𝖊𝖗𝖞𝖔𝖓𝖊 𝖒𝖆𝖙𝖙𝖊𝖗𝖘...\n\n\n<t:1583277337:R> <3"
Upvotes: 1
Views: 31
Reputation: 106
Example with group name:
<t:(?<timestamp>\d*):R>
Try it here https://regex101.com/
Upvotes: 2
Reputation: 7555
I won't give you the full solution, but here is the logic:
<t:
, in sequence:R>
You can use this regex in String#replace
. The replace
method can accept a callback as its second argument for a more powerful parsing of a match. In this case, you can process the string in the replace
callback to whatever text you need
Upvotes: 3