Solved

regex pattern to delete a pattern i need  for forward backslash and reverse backslash

Posted on 2014-04-10
8
1,959 Views
Last Modified: 2014-04-13
vba excel 2010

The following code works for dashes -
as in previous question:

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_28392904.html
before:
A-1195-004-AS
AT-11-4
AT-11-400
TR-1151-404
F-16441
AK - 5230
AK- 52309 -  500
RYB- 921 - 002
VB-9211-0-5-13
RYB-922-12

After:
A1195004AS
AT114
AT11400
TR1151404
F16441
AK5230
AK52309500
RYB921002
VB92110513
RYB92212




    Static oRE As Object
'
    If oRE Is Nothing Then
        Set oRE = CreateObject("vbscript.regexp")
        oRE.Global = True
    End If
    oRE.Pattern = "(?:([A-Z]+[0-9]*)\s*-\s*(?:([A-Z0-9]*)\s*-\s*)?(?:([A-Z0-9]*)\s*-\s*)?(?:([A-Z0-9]*)\s*-\s*)?)|([0-9]+)\s*-\s*([A-Z]+[0-9]*)(?:\s*-\s*([A-Z0-9]*))?(?:\s*-\s*([A-Z0-9]*))?"
    cD = oRE.Replace(cD, "$1$2$3$4$5$6$7$8")

Open in new window


I do not want it to delete patterns like fraction:
1/2  or 3-1/2 or 3 1/2 or 16/32


I need this regex to work for the following patterns BUT NOT in the same regex call
before:
LU250/40/H/ECO
LU310/H/ECO
CMH39/MR16/UL93\SP
CMH39/MR16/UL93/FL
CMH39/MR16/UL93WFL
F28T8/XL\SPX35\ECO
CMHi\23P38/FL/ECO

After:
LU25040HECO
LU310HECO
CMH39MR16UL93SP
CMH39MR16UL93FL
CMH39MR16UL93WFL
F28T8XLSPX35ECO
CMHi23P38FLECO

Thanks
fordraiders
0
Comment
Question by:fordraiders
  • 5
  • 3
8 Comments
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39991835
So basically you want to strip the "/" and "\", but still want to keep them on this types:
1/2-20
1/4-20
1/4-2
1/3-35
1/8-10

Please confirm.
0
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39991888
Pattern:
"([A-Z]\w*)[/\\](\w*)[/\\](\w*)[/\\]?(\w*)[/\\]?(\w*)[/\\]?"
replacement
$1$2$3$4$5

Open in new window

works for the following:
LU250/40/H/ECO
LU310/H/ECO
CMH39/MR16/UL93\SP
CMH39/MR16/UL93/FL
CMH39/MR16/UL93WFL
F28T8/XL\SPX35\ECO
CMHi\23P38/FL/ECO
1/2-20
1/4-20
1/4-2
1/3-35
1/8-10
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39992119
dan, sorry yes...
to your question

keep in tact:
1/2-20
1/4-20
1/4-2
1/3-35
1/8-10

or

1/4
13/32
1/5
1-1/5
23 1/2
23-1/2

etc...
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39992143
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39992772
ok, is this correct ?

  If oRE Is Nothing Then
        Set oRE = CreateObject("vbscript.regexp")
        oRE.Global = True
    End If
    oRE.Pattern = "([A-Z]\w*)[/\\](\w*)[/\\](\w*)[/\\]?(\w*)[/\\]?(\w*)[/\\]?"

   cD = oRE.Replace(cD, "$1$2$3$4$5")
0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39993284
Looks correct.
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 39998252
Thanks working fine.
0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39998255
Glad I could help!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question