+ Reply to Thread
Results 1 to 23 of 23

extract a string from variable text

  1. #1
    Registered User
    Join Date
    09-20-2010
    Location
    islamabad
    MS-Off Ver
    Excel 2019
    Posts
    97

    extract a string from variable text

    Dear Experts

    I would like to define a excel IS number (SEARCH) formaula to help me fetch a specified string from the variable alerts like this one

    T1133
    T1071.001

    From variable alerts rows like some time alerts are with _ some time the string start after a SPACE and some its under Brackets ()

    mitre_T1071.001 Communication with known Bad ip's
    mitre T1110.003 Multiple Users Attempting To Authenticate Using Explicit Credentials
    mitre_t1033_1 System User Discovery Net Commands/Alert
    Network Sniffing 2 (MITRE 1040) /Alert

    can you create a Search Is number formula that extract the T1133 as single number as well with dots from variable alerts name ?

    e.g. a formula that search MITRE with _ with () and with dots and copy the adjacent value in the next columns as T1133.001 or T1133
    =IF(ISNUMBER(SEARCH("MITRE"
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    04-27-2015
    Location
    Abu Dhabi, U.A.E
    MS-Off Ver
    Office 365 | 2016
    Posts
    697

    Re: extract a string from variable text

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,411

    Re: extract a string from variable text

    You can put this in C2 (say), and then copy down:

    =IF(ISNUMBER(SEARCH("Mitre",A2)),LEFT(MID(SUBSTITUTE(A2,")"," "),SEARCH("Mitre",A2)+6,FIND(" ",SUBSTITUTE(A2,")"," "),SEARCH("Mitre",A2)+6)-6)&" ",FIND(" ",MID(SUBSTITUTE(A2,")"," "),SEARCH("Mitre",A2)+6,FIND(" ",SUBSTITUTE(A2,")"," "),SEARCH("Mitre",A2)+6)-6)&" ")-1),"")

    You may have to use semicolons ( ; ) instead of commas ( , ) in the formula, depending on your regional settings.

    It gets all the numbers, but some have some other text as there are other symbols in the data ("_" and "-", and so on).

    Hope this helps.

    Pete

  4. #4
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,175

    Re: extract a string from variable text

    Or try this in C2:

    =IFERROR(TRIM(LEFT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(REPLACE(A2,1,SEARCH("Mitre",A2)+5,""),")"," "),"_"," ")," ",REPT(" ",100)),100)),"")
    Last edited by Phuocam; 11-16-2021 at 09:24 AM.

  5. #5
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: extract a string from variable text

    In FILTERXML() terms...

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Not perfect yet.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,768

    Re: extract a string from variable text

    UDF

    Please Login or Register  to view this content.
    Assumes required field starts with"T1" or "1"
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  7. #7
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,222

    Re: extract a string from variable text

    Please try

    =MID(LEFT(A2,MIN(FIND({" ",")","_"},A2&")_ ",SEARCH("mitre",A2)+6))-1),SEARCH("mitre",A2)+6,20)
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: extract a string from variable text

    My final master piece FILTERXML()

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: extract a string from variable text

    My final master piece (bullet proof correction) FILTERXML()


    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,505

    Re: extract a string from variable text

    How about this Regex

    Please Login or Register  to view this content.
    Last edited by JEC.; 11-16-2021 at 04:55 PM.

  11. #11
    Registered User
    Join Date
    09-20-2010
    Location
    islamabad
    MS-Off Ver
    Excel 2019
    Posts
    97

    Re: extract a string from variable text

    Quote Originally Posted by Phuocam View Post
    Or try this in C2:

    =IFERROR(TRIM(LEFT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(REPLACE(A2,1,SEARCH("Mitre",A2)+5,""),")"," "),"_"," ")," ",REPT(" ",100)),100)),"")
    can you try to add few more conditions for these three strings

    MITRE_T1102.002-Proxy outgoing persistent traffic direct to external ip result T1102.002-Proxy
    MITRE-T1090.002-Long Established Connection Over Proxy result= T1090.002-Long
    MITRE-T1001.Data Obfuscation result =T1001.Data

    I wanted to see them without .data -Proxy and -Long

    thanks u

  12. #12
    Registered User
    Join Date
    09-20-2010
    Location
    islamabad
    MS-Off Ver
    Excel 2019
    Posts
    97

    Re: extract a string from variable text

    Quote Originally Posted by DJunqueira View Post
    My final master piece (bullet proof correction) FILTERXML()


    Formula: copy to clipboard
    Please Login or Register  to view this content.
    This is working perfectly , can you please share the logic of each check I wanted to understand how this formula is checking multiple conditions one by one with Translate and NOT starts conditions

  13. #13
    Registered User
    Join Date
    09-20-2010
    Location
    islamabad
    MS-Off Ver
    Excel 2019
    Posts
    97

    Re: extract a string from variable text

    @DJunqueira just one string is still showing.data

    MITRE-T1001.Data Obfuscation T1001.Data
    is it possible to remove .data from here ?

  14. #14
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: extract a string from variable text

    Quote Originally Posted by esaji View Post
    This is working perfectly, can you please share the logic of each check I wanted to understand how this formula is checking multiple conditions one by one with Translate and NOT starts conditions
    Trying to explain:
    The formula has two main parts, the SUBSTITUTE() part inside FILTERXML() and the part at the end of this function, after //d (green part).

    =SUBSTITUTE(FILTERXML("<F><d>"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,"_"," "),"-"," "),")",") ")," ","</d><d>")&"</d></F>","//d[translate(.,'1234567890','')!=. and string-length()>3 and not(starts-with(., 'P'))][1]"),")","")

    The blue SUBSTITUTE() part I substituted "_" ; "-" for space " " and ")" for ") " because otherwise FILTERXML function would transform some strings into numbers (ie: Spearphishing Attachment (MITRE 1566.001) / Alert) were 1566.001 would loose the point separator and also other numbers would return as numbers, what wasn't desired. The first SUBSTITUTE(), takes care of the ")" character outside of FILTERXML() funcion.

    [/COLOR]SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,"_"," "),"-"," "),")",") ")

    In the second part translate(.,'1234567890','')!=. did most of the work, separating strings that had numbers, but were not numbers, from the rest. string-length()>3 and not(starts-with(., 'P'))][1] took care of some particular cases, some texts that were small and had numbers like P2P; 8; F5; v2, and a word Part2 was also showing up. From that point I had 7zip spilling out and I took care with [1].

    [translate(.,'1234567890','')!=. and string-length()>3 and not(starts-with(., 'P'))][1]"

  15. #15
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: extract a string from variable text

    For the very particular case

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  16. #16
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,505

    Re: extract a string from variable text

    Tried my UDF? Getting rid of .data as well

  17. #17
    Registered User
    Join Date
    09-20-2010
    Location
    islamabad
    MS-Off Ver
    Excel 2019
    Posts
    97

    Re: extract a string from variable text

    @DJunqueira thank you so much and would love to subscribe you if you are teaching excel on youtube - I really appriciate for saving my life and this task and the time you spend in beautifully explaining the formula hats off

    thank you so much !!!!!

  18. #18
    Registered User
    Join Date
    09-20-2010
    Location
    islamabad
    MS-Off Ver
    Excel 2019
    Posts
    97

    Re: extract a string from variable text

    I have not tried it ,will it convert the sheet macro enabled excel file ? a function i have to use with that file ?

  19. #19
    Registered User
    Join Date
    09-20-2010
    Location
    islamabad
    MS-Off Ver
    Excel 2019
    Posts
    97

    Re: extract a string from variable text

    Quote Originally Posted by DJunqueira View Post
    For the very particular case

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    is this will part of first formula plus second as i cant see the selected Row like A2 ? currently excel is throwing error

    Please Login or Register  to view this content.

  20. #20
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,505

    Re: extract a string from variable text

    Open Vba, add a module and paste the UDF
    Then call the function in Excel like a normal function.

    Give it a try!

    =jec(A1)

  21. #21
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: extract a string from variable text

    Quote Originally Posted by esaji View Post
    @DJunqueira thank you so much and would love to subscribe you if you are teaching excel on youtube - I really appriciate for saving my life and this task and the time you spend in beautifully explaining the formula hats off
    thank you so much !!!!!
    You are welcome and tank you for your kind words.

  22. #22
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: extract a string from variable text

    Quote Originally Posted by esaji View Post
    is this will part of first formula plus second as i cant see the selected Row like A2 ? currently excel is throwing error
    Big formula now:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Could be much smaller with the LET() function.
    Attached Files Attached Files

  23. #23
    Registered User
    Join Date
    09-20-2010
    Location
    islamabad
    MS-Off Ver
    Excel 2019
    Posts
    97

    Re: extract a string from variable text

    Quote Originally Posted by DJunqueira View Post
    Big formula now:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Could be much smaller with the LET() function.
    perfect and thank you much for valuable efforts and time to make this wonderful end result what i was looking for

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] extract text form text string( extract 5 charactors in front of all left parenthese)
    By happyexcel2021 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-30-2021, 06:05 PM
  2. [SOLVED] Extract string from variable length string
    By JeffGrant in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-30-2021, 03:47 AM
  3. [SOLVED] Extract a variable length number from within a text string
    By Kirk3737 in forum Excel General
    Replies: 2
    Last Post: 10-27-2020, 02:27 PM
  4. [SOLVED] How to extract a piece of a string variable, and assign to a new variable
    By jmccoughlin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-04-2015, 11:50 PM
  5. [SOLVED] Extract data from variable text string into seperate columns
    By kinnywayne in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-29-2014, 04:43 PM
  6. Extract Variable Length Text String
    By sshot1 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-12-2012, 06:21 PM
  7. EXTRACT TEXT FROM TEXT STRING:The names are of variable length
    By carricka in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-08-2005, 06:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1