Extract text between symbols

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to extract text from a string which will contain:

<sometext>/the text I want/<sometext>

The beginning and ending text will vary in length, but the text I want will
be between the two "/".

I am also looking to extract the text after the second "/", in a different
operation.

The data will change, so I want to write this as a template.

Any help is appreciated.

Thanks
 
With text in cel A1

Try something like this:
B1: =LEFT(MID(A1,FIND("/",A1)+1,255),FIND("/",MID(A1,FIND("/",A1)+1,255))-1)

Does that help?
***********
Regards,
Ron

XL2002, WinXP
 
try this
Sub extracttext()
For Each c In Selection
fb = InStr(1, c, "/") + 1
'MsgBox fb
sb = InStr(fb + 1, c, "/")
'MsgBox sb
ms = Mid(c, fb, sb - fb)
MsgBox ms
rest = Right(c, Len(c) - sb)
MsgBox rest

Next c
End Sub
 
I would like to extract text from a string which will contain:

<sometext>/the text I want/<sometext>

The beginning and ending text will vary in length, but the text I want will
be between the two "/".

I am also looking to extract the text after the second "/", in a different
operation.

The data will change, so I want to write this as a template.

Any help is appreciated.

Thanks

If the strings are less than 256 characters long, then you could download and
install Longre's free (and easily distributable) morefunc.xll add-in from
http://xcell05.free.fr/.

Then use this formula:

=REGEX.MID(A1,"(?<=/).*?(?=/)")


--ron
 
If the strings are less than 256 characters long, then you could download and
install Longre's free (and easily distributable) morefunc.xll add-in from
http://xcell05.free.fr/.

Then use this formula:

=REGEX.MID(A1,"(?<=/).*?(?=/)")


--ron

Oh, for the text after the second "/"

=REGEX.SUBSTITUTE(A1,".*/.*/")
--ron
 
Thank you. This worked well for the text between the symbols.
Could you offer something that would find the text after the second "/"?

TIA
 
Give this code a try...

Dim YourText As String, Parts() As String
.......
.......
YourText = "<sometext>/the text I want/<sometext>"
Parts = Split(YourText, "/")
If UBound(Parts) > 1 Then
ReturnValue = Parts(1)
Else
' The text you YourText did not contain at least two slash
' symbols, so handle the error here in anyway that you want to
End If
 
Back
Top