Results 1 to 6 of 6

regexp character exclude \r and \n

Threaded View

  1. #1
    Registered User
    Join Date
    12-25-2014
    Location
    Bourgogne, France
    MS-Off Ver
    2003
    Posts
    2

    regexp character exclude \r and \n

    Hello forum members,

    This is my 1st post, first of all I want to say hello to everyone here

    My problem is this:

    I would like to extract, from the whole string the string that immediately precedes the parentheses
    The cells contain several string separated by a carriage return – linefeed

    my data looks something like this - I Need an Output like this

    ELMS (United Autosports)
    IMSA (Action Express) ------> ELMS IMSA

    WRC (Hyundai) ------> WRC

    WEC (Toyota)
    Formula E (Renault)
    Day+Seb (Rebellion) -------> WEC Formula E Day+Seb

    NASCAR Cup
    (JTG Daugherty) -------> NASCAR Cup

    In the attached file, the values are written in column A starting at A2
    Very grateful for your help
    Option Explicit
    Sub test()
    Dim r As Range, i As Long
    Dim RegX As Object
        Set RegX = CreateObject("VBScript.RegExp")
        With RegX
            .Pattern = "([^\(]+)? ?\(([^\(\)]+)\)"
            .Global = True
        End With
        With Sheets("Liste")
            For Each r In .Range("a2", .Range("a" & .Rows.Count).End(xlUp))
                If RegX.test(r.Value) Then
                    For i = 0 To RegX.Execute(r.Value).Count - 1
                        r(, i + 3).Value = RegX.Execute(r.Value)(i).submatches(0)
                    Next
                End If
            Next
        End With
    End Sub
    klin89
    Attached Files Attached Files
    Last edited by klin89; 04-19-2017 at 09:38 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. RegExp Pattern to remove special character
    By BS Singh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2014, 12:12 AM
  2. Formatting using Regular Expression (RegExp)
    By vnzerem in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2014, 10:03 AM
  3. [SOLVED] VBA RegExp
    By vnzerem in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-11-2014, 05:45 PM
  4. [SOLVED] RegExp function
    By pkiula in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 08-17-2013, 06:22 AM
  5. Error with Set RegExp equal to New RegExp vba
    By bdb1974 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-22-2011, 05:28 PM
  6. RegExp
    By YBrazeau in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-13-2010, 07:51 PM
  7. RegExp Pattern
    By MBCMDR in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-08-2009, 02:09 PM

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