+ Reply to Thread
Results 1 to 10 of 10

regular expression to extract multi instances of pattern from cell

  1. #1
    Registered User
    Join Date
    07-03-2010
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Question regular expression to extract multi instances of pattern from cell

    Hi I need some help with a regular expression I would like to search column r and each cell extract text with the following format from the cell there may be one or more match in each cell

    I need to pull out string likethese:

    Abcd-1-349 or Abcd 1 459
    • mixed case alpha always 4 chars
    • A space or - separater
    • A single digit number
    • A space or - separater
    • A 3 digit number

    A cells data might look like this

    Aaaaaa abcd-1-444 assessed cvgvvbb fvbb cghd-3-789 asdf-7-456 asdffcc


    So I want to return abcd-1-444 and cghd-3-789 and asdf-7-456

    any ideas would be very helpful

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: regular expression to extract multi instances of pattern from cell

    Do you need help with just the RE pattern or do you need more?

    If more, where is the data and where do you want the results? An example file with an expanded data set and the expected results would be a great help.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    07-03-2010
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: regular expression to extract multi instances of pattern from cell

    the regular expression mostly -

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: regular expression to extract multi instances of pattern from cell

    This pattern should work.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-03-2010
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: regular expression to extract multi instances of pattern from cell

    Thank you this is great but how can I return multiple matches from the cell

    txt = "ABC123A ASAS-1-123 fdfdf ABC123A ASAS-1-116-methyl-5-hepten-2-one"

    I'd like to return ASAS-1-123 and ASAS-1-116

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: regular expression to extract multi instances of pattern from cell

    Hello starfish_001,

    This macro will return an array of the parsed strings or empty if no are found.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  7. #7
    Registered User
    Join Date
    07-03-2010
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: regular expression to extract multi instances of pattern from cell

    Thank you that is great - I could only think of replacing the found string and then trying again until no more matches this is neater

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: regular expression to extract multi instances of pattern from cell

    Hello starfish_001,

    You're welcome.

  9. #9
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: regular expression to extract multi instances of pattern from cell

    Quote Originally Posted by starfish_001 View Post
    Thank you that is great - I could only think of replacing the found string and then trying again until no more matches this is neater
    Here's a simple guide if you're interested.

    Simple Regular Expression Tutorial for Excel VBA

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: regular expression to extract multi instances of pattern from cell


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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