Results 1 to 12 of 12

Thread: Regular Expression Construction Help[RESOLVED]

  1. #1

    Thread Starter
    Addicted Member perlmonk's Avatar
    Join Date
    Jan 2005
    Posts
    138

    Resolved Regular Expression Construction Help[RESOLVED]

    I'm using VBA for excel, and Im facing a problem.
    I have a string, for example abcde

    If the string (data in a cell) is as above, then its OK. Sometimes, the data recieved might have some apostrophes (") at the beginning or end. To capture this, I want to pattern match against every cell to account for the following strings

    "abcde
    abcde"
    "abcde"


    In all the above, the output shud be abcde. I found a lot of websites detailing out pattern matching for VB, but, I believe that its not the same for VBA for excel. For example..." are referred to as chr(34) as I recently dicovered.

    If someone could help me build the regex im looking for...I'd really appreciate it!!
    Last edited by perlmonk; Jan 13th, 2005 at 12:45 PM.

  2. #2
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: Regular Expression Construction Help

    Quote Originally Posted by perlmonk
    I'm using VBA for excel, and Im facing a problem.
    I have a string, for example abcde

    If the string (data in a cell) is as above, then its OK. Sometimes, the data recieved might have some apostrophes (") at the beginning or end. To capture this, I want to pattern match against every cell to account for the following strings

    "abcde
    abcde"
    "abcde"


    In all the above, the output shud be abcde. I found a lot of websites detailing out pattern matching for VB, but, I believe that its not the same for VBA for excel. For example..." are referred to as chr(34) as I recently dicovered.

    If someone could help me build the regex im looking for...I'd really appreciate it!!
    If you need to refer to a (") character inside of a literal string surrounded by (") characters, you can use 2 (") back-to-back which will allow a single (") inside of a string:

    VB Code:
    1. "This has 2 ""quotes"" inside it."

  3. #3

    Thread Starter
    Addicted Member perlmonk's Avatar
    Join Date
    Jan 2005
    Posts
    138

    Re: Regular Expression Construction Help

    Thanks for the suggestion...I will try it right away...do you have any suggestion as to how to pattern match any character after the ("), whether integer or character?

  4. #4
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: Regular Expression Construction Help

    Quote Originally Posted by perlmonk
    Thanks for the suggestion...I will try it right away...do you have any suggestion as to how to pattern match any character after the ("), whether integer or character?
    Using pattern matching implies a formatted input as an input argument to either an operator (Like, +, etc..) or a named function.

    Is this what you are doing? Please explain more.

  5. #5

    Thread Starter
    Addicted Member perlmonk's Avatar
    Join Date
    Jan 2005
    Posts
    138

    Re: Regular Expression Construction Help

    Quote Originally Posted by Dave Sell
    Using pattern matching implies a formatted input as an input argument to either an operator (Like, +, etc..) or a named function.

    Is this what you are doing? Please explain more.
    The input will be in the form of some data in an excel cell. This alphanumeric data, for the most part would be formatted correctly (meaning that the data would be as is, without any quotation marks or anything)...but sometimes the data might have quotation marks in the beginning, end or both...for example, if abc represents the correctly formatted data..the incorrect formatted data might be "abc or abc" or "abc"

    I want to trap these quotation marks, if present, and remove them.

    I hope this explains my problem..please let me know!! Thanks a bunch

  6. #6

    Thread Starter
    Addicted Member perlmonk's Avatar
    Join Date
    Jan 2005
    Posts
    138

    Re: Regular Expression Construction Help

    do you think adding the following reference to my list of references would help?

    Microsoft VBScript Regular Expressions 5.5...I found this in the References selection under tools.

    Also, found more info on this at http://visualbasic.about.com/od/usin...l/blregexa.htm

  7. #7
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: Regular Expression Construction Help

    Quote Originally Posted by perlmonk
    do you think adding the following reference to my list of references would help?

    Microsoft VBScript Regular Expressions 5.5...I found this in the References selection under tools.

    Also, found more info on this at http://visualbasic.about.com/od/usin...l/blregexa.htm
    Probably, but I've never used it.

  8. #8

    Thread Starter
    Addicted Member perlmonk's Avatar
    Join Date
    Jan 2005
    Posts
    138

    Re: Regular Expression Construction Help

    yea...this didnt work...am pretty disappointed.

    any suggestions??

  9. #9
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: Regular Expression Construction Help

    Quote Originally Posted by perlmonk
    yea...this didnt work...am pretty disappointed.

    any suggestions??
    You just have to use your
    VB Code:
    1. Instr()
    function.

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Regular Expression Construction Help

    You may want to post a thread in the VB.NET forum since more users would
    familiar with RegEx over there.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    Addicted Member perlmonk's Avatar
    Join Date
    Jan 2005
    Posts
    138

    Re: Regular Expression Construction Help

    Quote Originally Posted by RobDog888
    You may want to post a thread in the VB.NET forum since more users would
    familiar with RegEx over there.
    Hey thanks everyone...I'll try the Instr function, but im sure there is a shorter way by using regex.

    I'll post my prob in .NET section as well...thanks once again!!

  12. #12

    Thread Starter
    Addicted Member perlmonk's Avatar
    Join Date
    Jan 2005
    Posts
    138

    Re: Regular Expression Construction Help

    I fixed the issue using the replace function....sweeeeeeet .
    thanks everyone

Posting Permissions

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



Click Here to Expand Forum to Full Width