Find and extract a substring from a string

Little_Ghost

New Member
Joined
Dec 13, 2010
Messages
48
I've been reading around and found all kinds of problems that where like the one I'm having, but none of the solutions worked for me.
I have a list with lines liek these:

****** name="email" content="dl-departmentmailbox">
<p><a href="mailto:dl-departmentmailbox">dl-departmentmailbox</a></p>
<li><a href="http://holidayplanner/cgi-bin/scheduele.pl?config=dl-all-deps">dl-all-deps</a></li>
<form name="PlanningRequest" method="post" enctype="text/plain" action="mailto:dl-planningrequest@mycompany.com?subject=Planning Request">

What I want/need to do is go through those strings and look for the part that starts with "dl-".
Then I need to copy/extract that + whatever is behind it.

I can't find a way to do it because the leading characters differ as do the ones at the back and the position and length of the string it need to find.

Is there an (easy) way to do this??

Kind regards
 
it works as long as the dl- part is not mentioned twice, like:
Code:
<p><a href="mailto:dl-department2">dl-department2</a></p> 
<li><a href="mailto:dl-all_departments@company.com">dl-all_departments@company.com</a></li>

Changed it.
it now read:
Code:
=MID(A2;SEARCH("dl-";A2;1);SEARCH(""">";A2;1)-SEARCH("dl-";A2;1))
This works on ALLMOST all of the entries... still trying to fine-tune.
Thanks for all the help and tips so far
 
Upvote 0
I figured out why it still doesn't work on ALL entries:
Sometimes it will (for instance) encoutner the dl- at position 94 and encouter THE FIRST "> at position 55. This way, the "substraction" ends in a negative (because the ending character comes before the starting character).
Code:
 please contact <a href="mailto:person@company.com">Persons Name</a> or <a href="mailto:dl-department@company.com">dl-department@company.com</a>.</p>
Not sure how that could be solved though.
 
Upvote 0
If the end point has a numeric value ("dl-department1"> OR dl-department2">) as seen in both the examples provided you could try out the following:

The starting point begin the first instance for dl- and the end point being a numeric value

=MID(A1,SEARCH("dl-",A1,1),(MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))-SEARCH("dl-",A1,1)))
 
Upvote 0
Didn't view your last response before I responded. So the end point can vary as per the latest string example you provided
 
Upvote 0
=MID(A2,SEARCH("dl-",A2,1),SEARCH(""">",A2,SEARCH("dl-",A2,1))-SEARCH("dl-",A2,1))

Hopefully this should work; tested on all the example strings provided.
 
Upvote 0
=MID(A2,SEARCH("dl-",A2,1),SEARCH(""">",A2,SEARCH("dl-",A2,1))-SEARCH("dl-",A2,1))

Hopefully this should work; tested on all the example strings provided.

Only 1 or 2 left that are not working, but I'll just filter those out by hand.
Thanks!
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top