Fordraiders
asked on
regex pattern to delete a pattern i need for forward backslash and reverse backslash
vba excel 2010
The following code works for dashes -
as in previous question:
https://www.experts-exchange.com/questions/28392904/Regex-for-vba-in-taking-dashes-out-of-string-in-special-cases.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
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
The following code works for dashes -
as in previous question:
https://www.experts-exchange.com/questions/28392904/Regex-for-vba-in-taking-dashes-out-of-string-in-special-cases.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")
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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...
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...
ASKER
ok, is this correct ?
If oRE Is Nothing Then
Set oRE = CreateObject("vbscript.reg exp")
oRE.Global = True
End If
oRE.Pattern = "([A-Z]\w*)[/\\](\w*)[/\\] (\w*)[/\\] ?(\w*)[/\\ ]?(\w*)[/\ \]?"
cD = oRE.Replace(cD, "$1$2$3$4$5")
If oRE Is Nothing Then
Set oRE = CreateObject("vbscript.reg
oRE.Global = True
End If
oRE.Pattern = "([A-Z]\w*)[/\\](\w*)[/\\]
cD = oRE.Replace(cD, "$1$2$3$4$5")
Looks correct.
ASKER
Thanks working fine.
Glad I could help!
1/2-20
1/4-20
1/4-2
1/3-35
1/8-10
Please confirm.