Jump to content

Replace utility REGEX help


Recommended Posts

Hello,

 

I'm still a newb with this and am clearly going very wrong somewhere.

 

I'm trying to create a simple workflow for similarweb.com where I can copy and URL to the clipboard, extract the domain, and enter the query into the URL.

 

Where I'm going wrong is with the transformation - replacing the query with regex (that I found online). I think I must be using the replace functionality wrong, as currently it doesn't do anything.

 

Can anyone please advise?

 

Thanks!

 

image.png.cf7418457f395267baeb30ce129422e4.png

 

image.thumb.png.bcad3cbb1a06252413f385843ca501bd.png

 

/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n?]+)/img

 

image.thumb.png.5e82d4c8a9befd2ce7885949bdd15851.png

image.png

Link to comment

The text you’ve placed in with is the regular expression. You want that in the first text field, not the second. On the second field you add the replacing text, which in your case would be $1 (first capture group). But the regex text is itself incorrect for the text field, you need to remove the first / and the trailing /img, those are relevant in different contexts.

 

If all you want is to extract the domain from a given URL, there’s an Automation Task for that (Get URL Hostname). It does require that the URL be valid, i.e. contain the https://.


However, the workflow doesn’t seem set up to do what you describe, you’re not getting anything from the clipboard.


If the above doesn’t fix your problem, please describe your ultimate goal rather than the last step in the chain so we can arrive at the best solution.

Link to comment

@vitor Thank you.

 

I think my issue now lies in the correct regular expression.

 

The goal for the regex is to trim a URL to it's root domain - no "https://", no "www" or other subdomains, and nothing after the TLD e.g .com.

That way the rest of the workflow adds the trimmed domain into a URL thart is opened and works correctly. It only works with the root domain.

 

I'll have to check online and test some other regular expressions. One day I'll attempt to write regex from scratch, one day...

Link to comment
15 minutes ago, alfredpanda said:

The goal for the regex is to trim a URL to it's root domain - no "https://", no "www" or other subdomains, and nothing after the TLD e.g .com.

 

That’s exactly what the Automation Task does. You only have to ensure it’s a valid URL beforehand so you can e.g. have a Conditional which checks for that and add it if necessary:

nudITsu.png

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...