I have found the following Regular Expression very useful to look for a URL in a long text string:
(ftp:\/\/|www\.|https?:\/\/){1}[a-zA-Z0-9u00a1-\uffff0-]{2,}\.[a-zA-Z0-9u00a1-\uffff0-]{2,}(\S*)
Used on the following text string:
<td bgcolor="white" style="padding:5px !important;” class=“”><a href="https://www.jotformeu.com/uploads/Terke ... /DEMO.xlsx" class="">DEMO.xlsx</a></td>
... it will return this:
https://www.jotformeu.com/uploads/Terke ... /DEMO.xlsx"
It works very well with variables in Switch. The only problem is the dobbelt quote at the end of the string, so I changed the RegEx to this:
(ftp:\/\/|www\.|https?:\/\/){1}[a-zA-Z0-9u00a1-\uffff0-]{2,}\.[a-zA-Z0-9u00a1-\uffff0-]{2,}(\S[^"]*)
... adding [^"] to Group 2
Checking this in different online RegEx evaluators, it works fine, but if I use it in Switch, it breaks everything and only returns this: *)"].
Could anybody tell me how to change the RegEx to exclude the dobbelt quote at the end of the URL, AND have it work in Switch?
Help with RegEx
- TheCaptain
- Member
- Posts: 86
- Joined: Mon Jan 18, 2016 4:22 pm
- Location: London
Re: Help with RegEx
I've found Switch likes having this expression fully quantified i.e ... and often works best without the comma if that's possible.
Also, where I've had a longer expression, sometimes enclosing the entire thing once more in '(' and ')' can help.
from to this sort of thing.
Code: Select all
{2,}
Code: Select all
{2,6}
Also, where I've had a longer expression, sometimes enclosing the entire thing once more in '(' and ')' can help.
from
Code: Select all
(this{2})\b
Code: Select all
((this{2})\b)
Re: Help with RegEx
Excuse my ignorance, but I don't think I understand how this could solve the problem?
I need a way to exclude the double quote (") from the result that is returned. In a javascript RegEx this would workbut it can't be used inside Switch
I need a way to exclude the double quote (") from the result that is returned. In a javascript RegEx this would work
Code: Select all
[^"]
Re: Help with RegEx
Hi Terkelsen
This regexp seems to do it:
(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?
HTH
Loic
www.ozalto.com
This regexp seems to do it:
(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?
HTH
Loic
www.ozalto.com
Loïc Aigon
Enfocus PitStop Manager
Enfocus PitStop Manager
Re: Help with RegEx
Hi Loic,
That was a different approach but it solves the problem
Thanks a lot.
That was a different approach but it solves the problem

Thanks a lot.