Solved

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

Posted on 2014-04-10
8
1,876 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
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…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

810 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