Regex to find match of 2 strings in order
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

We have some data that looks like this (we call them domain paths)
Domain1.com > domain2.com> domain3.com> domain4.com

And

Domain2.com> domain3.com > domain4.com > domain1.com

We would like to query the above strings (domain paths) to find which ones have a specific couple of nodes in order. For example, find which ones had domain 1 before domain 4.

Ideally your regex and process each domain path looking for 2 specific domain nodes in a specific order. the two domains do not need to be contiguous but they do need to be in the right order

Can use https://regex101.com/ for testing your regex

Could you please provide sample input and output? Will the input always be the string "domain"+number or it can be any string? is it case sensitive?
mashtullah 10 days ago
awarded to Wuddrum
Tags
regex

Crowdsource coding tasks.

2 Solutions


Hi Qdev,

If I understand correctly this is what you need:

Domain2\.com.*domain4\.com

This is to test that Domain2.com is before domain4.com.
The important bit is to have .* in between the nodes.

Test: https://regex101.com/r/vFoxoq/1

hey we used Wuddrum's on this but i know you had a good solution base for it. sending tip
Qdev 10 days ago
Winning solution

Vlad's solution should be sufficient.

But if you specifically want to return the whole line then this should do: https://regex101.com/r/MOr9MQ/1

And for strictly contiguous domain paths: https://regex101.com/r/9XJxjG/1

Remember to escape domains. e.g. domain1.com should be domain1\.com when inserted into regex.

View Timeline