Extract text strings from cell ( regex available ) - mac

alex0182828

Board Regular
Joined
Jun 20, 2012
Messages
88
Office Version
  1. 365
Platform
  1. MacOS
I would like to be able to pull text strings matching this regex from a cell that would contain them ( cell also contains other words and may have the value as part of an url

^0x[a-fA-F0-9]{40}$

0xc8e78ad2573f5e16a286443aea2a6f1ba0c06b96
http://www.blahblah.com/0xc8e78ad2573f5e16a286443aea2a6f1ba0c06b96/wafflewaffle.cake​

However im on a mac and it seems the VBA addon to do this doesnt exisit. Can anyone help me ?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Unfortunately the regex library is not available (AFAIK). Since you are using Excel 2012 for mac, maybe try the following CSE-entered formula:

Excel Formula:
=MID(A1,MIN(IF(FREQUENCY(IF(ISNUMBER(SEARCH(MID(A1,ROW(A1:INDEX(A:A,LEN(A1))),1),"abcdef0123456789")),ROW(A1:INDEX(A:A,LEN(A1)))),IF(ISNUMBER(SEARCH(MID(A1,ROW(A1:INDEX(A:A,LEN(A1))),1),"abcdef0123456789")),0,ROW(A1:INDEX(A:A,LEN(A1)))))=40,ROW(A1:INDEX(A:A,LEN(A1))),LEN(A1)+1))-42,42)

This does **not** check the leading two characters are '0x', but if need be, this can be included in the above which would make it at least twice as long.
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Also do you always want to return the text before the last /
 
Upvote 0
thanks all :) i have updated my profile now thanks im on Office 365 Mac v16.69

The string does need to start with 0x and it should pull it no matter what the surrounding text or lack of so i have given 5 examples of cell context it could appear

VBA Code:
0xc8e78ad2573f5e16a286443aea2a6f1ba0c06b96

http://www.blahblah.com/0xc8e78ad2573f5e16a286443aea2a6f1ba0c06b96/wafflewaffle.cake

http://www.blahblah.com/0xc8e78ad2573f5e16a286443aea2a6f1ba0c06b96

this is a great one 0xc8e78ad2573f5e16a286443aea2a6f1ba0c06b96

check this out 0xc8e78ad2573f5e16a286443aea2a6f1ba0c06b96 looks good
 
Upvote 0
Well, that would make life a lot easier indeed. Not sure if all functions would be available (yet), but try:

Book1
AB
10xc8e78ad2573f5e16a286443aea2a6f1ba0c06b960xc8e78ad2573f5e16a286443aea2a6f1ba0c06b96
2http://www.blahblah.com/0xc8e78ad2573f5e16a286443aea2a6f1ba0c06b96/wafflewaffle.cake0xc8e78ad2573f5e16a286443aea2a6f1ba0c06b96
3http://www.blahblah.com/0xc8e78ad2573f5e16a286443aea2a6f1ba0c06b960xc8e78ad2573f5e16a286443aea2a6f1ba0c06b96
4this is a great one 0xc8e78ad2573f5e16a286443aea2a6f1ba0c06b960xc8e78ad2573f5e16a286443aea2a6f1ba0c06b96
5check this out 0xc8e78ad2573f5e16a286443aea2a6f1ba0c06b96 looks good0xc8e78ad2573f5e16a286443aea2a6f1ba0c06b96
60xc8e78ad2573f5e16a286443aea2a6f1ba0c06b97 or 0xc8e78ad2573f5e16a286443aea2a6f1ba0c06b960xc8e78ad2573f5e16a286443aea2a6f1ba0c06b97
Sheet5
Cell Formulas
RangeFormula
B1:B6B1=MAP(TOCOL(A:A,3),LAMBDA(r,LET(x,SEQUENCE(LEN(r)+1),y,MID(r&"|",x,1),z,ISNUMBER(SEARCH(y,"abcdef0123456789")),v,MID(r,FILTER(x,DROP(FREQUENCY(IF(z,x),IF(z,0,x))=40,-1))-42,42),@FILTER(v,EXACT(LEFT(v,2),"0x")))))
Dynamic array formulas.


The idea here is that `MAP()` will iterate over each value in column A and will return the 1st occurence of a valid pattern, hence the implicit intersection on the last `FILTER()`.
 
Upvote 1
Solution
I'm glad it worked. For good measure, you can replace the '=40' part into '>39' since the patterns could then also be found if they are overlapping eachother.
 
Upvote 0
If it always starts with '0x' and the string is always the same length and you have the textafter function then the below is a shorter formulae:
Excel Formula:
=LEFT("0x" & TEXTAFTER(A1,"0x"),42)

If the string varies in length then it will not be an option
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,850
Members
449,194
Latest member
HellScout

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