1

Is there a way to get the URL from below text using freemarker replace or matches available in freemarker built ins.

<#assign text = "There are some text with url like https://www.google.com" />

I Want something like below to get the url from this text.

${text?matches('some freemarker regex')}  // expected: https://www.google.com

I searched on internet and found the same in javascript but don't know how to convert it in freemarker. how to detect and get url on string javascript

Thanks for help in advance!

Umutambyi Gad
  • 4,082
  • 3
  • 18
  • 39
Neeraj Kumar
  • 436
  • 1
  • 4
  • 13
  • Does this answer your question? [Regular expression to match URLs in Java](https://stackoverflow.com/questions/163360/regular-expression-to-match-urls-in-java) – msmolcic Jul 27 '20 at 16:17

1 Answers1

1

You don't really need regex for this. Try something like:

<#assign text = "There are some text with url like https://www.google.com" >
<#list text?split(" ") as x>
<#if x?starts_with("http")>${x}</#if>
</#list>

Output:

https://www.google.com
Jack Fleeting
  • 24,385
  • 6
  • 23
  • 45