0

I have this string

Weiss,Emery/Ap #519-8997 Quam. Street/Hawaiian Gardens,IN - 79589|10/13/2010

how do I get the Hawaiian Gardens only?

I already tried Using some

=mid(left(A1,find("/",A1)-1),find(",",A1)+1,len(A1))

it gives me emery instead

3
  • This might be very hard to handle using pure Excel. If you have long term needs similar to this, it might be worthwhile to spend some time learning about VBA for Excel. From VBA code, you would have a number of options for handling this problem. Commented Jun 12, 2019 at 5:24
  • 1
    are there always two / before the search term? Commented Jun 12, 2019 at 5:47
  • Yes, there is always / and , between the string. Commented Jun 12, 2019 at 7:10

2 Answers 2

2

If there are always two slashes before the string you want to extract, based onTyler M's answer you can use this

=MID(E1,
     FIND("~",SUBSTITUTE(E1,"/","~",2))+1,
     FIND(",",RIGHT(E1,LEN(E1)-FIND("~",SUBSTITUTE(E1,"/","~",2))))-1
     )

This substitutes the second occurence of / with a character which normally would not occur in the address, thus making it findable.

Sign up to request clarification or add additional context in comments.

Comments

2

Was your intention to also include Google Spreadsheets (looking at your title)? If so,you can use the REGEXEXTRACT() function. For example in B1

=REGEXEXTRACT(A1,"\/([\w\s]*)\,")

enter image description here

In Excel you could build a UDF using this regex rule like so (as an example):

Function REGEXEXTRACT(S As String, PTRN As String) As String

'We will get the last possible match in your string...
Dim regex As Object
Set regex = CreateObject("VBScript.RegExp")
With regex
    .Pattern = PTRN
    .Global = True
End With

Set matches = regex.Execute(S)
For Each Match In matches
    If Match.SubMatches.Count > 0 Then
        For Each subMatch In Match.SubMatches
            REGEXEXTRACT = subMatch
        Next subMatch
    End If
Next Match

End Function

Call the function in B1 like so:

=REGEXEXTRACT(A1,"\/([\w\s]*)\,")

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.