+ Reply to Thread
Results 1 to 22 of 22

RegEx pattern

  1. #1
    Forum Contributor
    Join Date
    07-11-2010
    Location
    Minneapolis, USA
    MS-Off Ver
    Excel 2016
    Posts
    308

    RegEx pattern

    Very new to RegEx,
    I have in cells in a column like:
    Please Login or Register  to view this content.
    I want
    Please Login or Register  to view this content.
    I have tried patterns like:
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    Not getting it

    Thanks

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,616

    Re: RegEx pattern

    What is the relation to Excel?

  3. #3
    Forum Contributor
    Join Date
    07-11-2010
    Location
    Minneapolis, USA
    MS-Off Ver
    Excel 2016
    Posts
    308

    Re: RegEx pattern

    I am using it in VBA

  4. #4
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,616

    Re: RegEx pattern

    Thanks. VBA is not my forte. Didn't know that. Learned something today

  5. #5
    Forum Contributor
    Join Date
    07-11-2010
    Location
    Minneapolis, USA
    MS-Off Ver
    Excel 2016
    Posts
    308

    Re: RegEx pattern

    I am using like this
    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: RegEx pattern

    If you just the word stuff
    Please Login or Register  to view this content.
    Or


    Please Login or Register  to view this content.
    Last edited by AB33; 02-14-2015 at 04:38 PM.

  7. #7
    Forum Contributor
    Join Date
    07-11-2010
    Location
    Minneapolis, USA
    MS-Off Ver
    Excel 2016
    Posts
    308

    Re: RegEx pattern

    Apologies about my sloppy question, I have cells like:
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    There are more possibilities but all end with
    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: RegEx pattern

    What do you want to return or extract?

  9. #9
    Forum Contributor
    Join Date
    07-11-2010
    Location
    Minneapolis, USA
    MS-Off Ver
    Excel 2016
    Posts
    308

    Re: RegEx pattern

    From the above
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    I want to remove the
    Please Login or Register  to view this content.
    from the ends of all the strings in my range

    Thanks

  10. #10
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: RegEx pattern

    Hi..

    Rather than using Regex and most probably a loop.. try this..

    Please Login or Register  to view this content.

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: RegEx pattern

    Nevermind - It didn't work
    Last edited by xladept; 02-14-2015 at 06:58 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  12. #12
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: RegEx pattern

    lol.. mm.. yeap.. I may have gone a bit overboard on that one..

  13. #13
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: RegEx pattern

    No - you didn't go overboard - my condensation worked when there was just one line - but, you're convolutions were necessary!

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

    Re: RegEx pattern

    Why RegExp?

    Just replace ", Other (please specify)" with "" should do....

    If you insist
    Please Login or Register  to view this content.

  15. #15
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: RegEx pattern

    Jindon's code is much better than mine and works in all circumstances, but I just post it.
    Attached Files Attached Files
    Last edited by AB33; 02-14-2015 at 07:17 PM.

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

    Re: RegEx pattern

    Ah, I just remembered your thread.

    http://www.excelforum.com/excel-prog...g-nothing.html

    For the learning purpose...

    You want to remove

    Stuff, Other (please specify)

    So the patter should be

    "(, Other \(please specify\))"

    You missed a space after "Other"...

  17. #17
    Forum Contributor
    Join Date
    07-11-2010
    Location
    Minneapolis, USA
    MS-Off Ver
    Excel 2016
    Posts
    308

    Re: RegEx pattern

    Thank you all for your input I greatly appreciate the different approaches, though I admit to being a bit lost on apo's solution

    I was also trying to use the code below, but it was not replaceing the (please specify) in ", Other(please specify)", I could replace ", Other" then "(please specify)" but not ", Other(please specify)" in one go
    Please Login or Register  to view this content.
    Last edited by capson; 02-15-2015 at 12:08 PM.

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

    Re: RegEx pattern

    Quote Originally Posted by capson View Post
    I have in cells in a column like:
    Please Login or Register  to view this content.
    I want
    Please Login or Register  to view this content.
    As I mentioned already, you missed a space after "Other"

    You need to replace "Other (please specify)"

  19. #19
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: RegEx pattern

    Hi capson,

    The beauty of APO's routine is that it does all the replacements at once - so it should be quickest.

    Jindon's routine is vintage Jindon - elegantly cryptic - but it processes each phrase, not the whole thing all at once.

    Jindon initially pointed out that you only needed a simple replacement - this routine processes each phrase so it can't be as quick as APO's routine:

    Please Login or Register  to view this content.

  20. #20
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: RegEx pattern

    Hi capson..

    though I admit to being a bit lost on apo's solution
    I will try to break it down for you so you might understand what i was thinking..

    Note to anyone else: If any of the following (technically or terminology) is incorrect... please let me know..

    First.. try stepping through this code.. its' basically the same as the 1 line of code but I have separated it so each line does a specific thing..

    IMPORTANT.. make sure your "Locals" window is open.

    In the VB Editor.. go to "View" and enable the "Locals" window.

    Please Login or Register  to view this content.
    You will see something like this..

    Locals.png

    Explanation:
    a = Shows what the values would look lke when put into a 2 Dimensional array.

    b = Transpose the values from the array into a 1 Dimensional array. This is so we can use the Join command next.

    c = Join all the elements in the 1 Dimensional array (by the vbcrlf delimiter) into 1 long string.

    d = Replace all instances of ", Other (please specify)" with "" in the long string.

    e = Use the Split command (using the vbcrlf again as the delimter) to separate the lines into tseparate elements of a 1 Dimensional array.

    f = Transpose it back to a 2 Dimensional array so it can written to the sheet correctly.

    I hope that helps..

  21. #21
    Forum Contributor
    Join Date
    07-11-2010
    Location
    Minneapolis, USA
    MS-Off Ver
    Excel 2016
    Posts
    308

    Re: RegEx pattern

    Wow, that helped a lot, I think I actually understood it!!!

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

    Re: RegEx pattern

    You are all misunderstading what I offered at the first place, REPLACE

    Please Login or Register  to view this content.

    Or even

    Please Login or Register  to view this content.
    Last edited by jindon; 02-15-2015 at 07:06 PM. Reason: fixed a Type

+ 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] RegEx pattern, code exacuting but doing nothing
    By capson in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-23-2015, 03:48 PM
  2. Regex: Matching pattern to split a cell data
    By DavidRoger in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-01-2014, 07:31 AM
  3. Regex - establishing a pattern
    By twckfa16 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-30-2014, 11:06 AM
  4. [SOLVED] RegEx pattern to extract multiplelines title in TXT file
    By p24leclerc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-06-2014, 08:39 PM
  5. Need a new regex .pattern for comparison code
    By Swiss Cheese in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-06-2012, 09:16 PM

Tags for this Thread

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