+ Reply to Thread
Results 1 to 15 of 15

Remove first and last letter using regex

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Remove first and last letter using regex

    Hello everyone

    I have a string say [email protected]
    I can use the usual functions to get rid of the first letter and the last letter before the symol @ so as the result would be [email protected]
    But I need a regex pattern that would do that

    Thanks advanced for help
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Remove first and last letter using regex


    Hi Yasser !

    I'm too lazy today to play with Regex as it needs a single codeline with the VBA text functions …

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Remove first and last letter using regex

    Thanks a lot. I tried this pattern but doesn't work for me
    Please Login or Register  to view this content.
    I know well how to use the VBA functions but I am training on regular expressions so thanks a lot.

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Remove first and last letter using regex

    I am trying to get the two groups
    Please Login or Register  to view this content.
    Each group works well lonely but when use the two groups together I didn't get the both of them

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Remove first and last letter using regex

    I could use this pattern and when trying the code to extract all the matches I got the desired results
    Please Login or Register  to view this content.
    How can I remove those matches?
    This is the code
    Please Login or Register  to view this content.

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

    Re: Remove first and last letter using regex

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Remove first and last letter using regex

    Amazing my tutor jindon. That's exactly what I am trying to do...You did it magically
    But I need to get the pattern .. Can you please give it a simple explanation?

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

    Re: Remove first and last letter using regex

    Match to any one character at the beginning or any one character followed by @.

  9. #9
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Remove first and last letter using regex

    Thanks a lot. What does this symbol mean (?=@). What's the question mark refer to? Does this mean not to include the @ symbol

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

    Re: Remove first and last letter using regex

    Open bracket with a question mark will avoid back reference of the grouped string up to closing bracket.

  11. #11
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Remove first and last letter using regex

    Sorry this is beyond my thinking. What do you mean by avoiding back reference?

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

    Re: Remove first and last letter using regex

    What do you know about regular expressions?
    If you want to learn it, google it for yourself first.
    I don't want to explain from the very basics, sorry.

  13. #13
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Remove first and last letter using regex

    I already read about it .. and here's the tutorial I have read
    https://stackoverflow.com/questions/22542834/

    and the question mark means( Match zero or one of the pattern defined before it.)
    but I am confused about using the equal sign and the brackets.

  14. #14
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Remove first and last letter using regex

    Yasser,

    on my profile messages you asked for a sample using Evaluate but I won't use it for your need as described,
    just the VBA text functions for a single codeline …

  15. #15
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Remove first and last letter using regex

    Thanks a lot, Mr. Marc for your sharing. I like you to share absolutely.

+ 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] Instr with RegEx - Runtime error 5017 (RegEx Code provided)
    By dluhut in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-28-2018, 05:02 PM
  2. [SOLVED] VBA Regex to remove text between two -'s
    By beaglesBuddy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-26-2018, 08:18 PM
  3. [SOLVED] Remove substring with RegEx
    By capson in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-11-2018, 12:12 AM
  4. Remove a certain letter from a label
    By DevKapadia16 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-05-2017, 03:24 AM
  5. [SOLVED] remove last character if any letter
    By s@skia in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-23-2013, 11:23 AM
  6. Remove last letter + all following characters
    By Niclal in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 06-10-2013, 09:41 AM
  7. Using regex in vba to remove emty xml tags - is it possible?
    By Laurentius77 in forum Excel General
    Replies: 0
    Last Post: 06-23-2012, 03:10 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