Link to home
Start Free TrialLog in
Avatar of acunaara
acunaara

asked on

Using VBscript & RegEx, how can I match lines starting with Oracle word

Using VBscript & RegEx, how can I match lines starting with Oracle word in the below sample:

"OracleJobScheduler"                                check      12            TEST
"OracleMTSRecoveryService"                  check      87            Down
"OracleOraDb11g_homeTNSListenr"      check       90            Up
"OracleService"                                  check        78            TEST

and replacing the lines as below
"OracleJobScheduler"                                DONE      100            UP
"OracleMTSRecoveryService"                  DONE      100            UP
"OracleOraDb11g_homeTNSListenr"      DONE       100            Up
"OracleService"                                  DONE        100            UP
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

User this RegEx
"Oracle.*
https://regex101.com/r/y45d49/1

For each match
Replace "check" with "|"
Then do a Split on "|" to get and array.
Build new string with the first index of array & "DONE 100 UP"
SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of acunaara
acunaara

ASKER

hi fernando
and for a single line like this one?
"OracleOraDb11g_homeTNSListenr"      DONE       100            Up
@acunaara

Please post the exact lines/strings your VBScripts is encountering.  Also, please answer the question posted earlier about quotation mark characters in the input.
Here is working VBS

Option Explicit

Dim objRegEx
Dim strSearchString
Dim strNewString

Set objRegEx = CreateObject("VBScript.RegExp")

objRegEx.Global = True   
objRegEx.IgnoreCase = True
objRegEx.Pattern = "check.*"

strSearchString = _
"""OracleJobScheduler""                                check      12            TEST" & vbCrLf & _
"""OracleMTSRecoveryService""                  check      87            Down" & vbCrLf & _
"""OracleOraDb11g_homeTNSListenr""      check       90            Up" & vbCrLf & _
"""OracleService""                                  check        78            TEST"

strNewString = objRegEx.Replace(strSearchString, "DONE      100            UP")

Wscript.Echo strNewString

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do OP want VBS or VB? Confused...
I know but Fernando is posting VB.net... Mine is VBS
@aikimark, when I posted my initial comment  I thought I saw VB .Net as one of the tags. I did not make my second post until the author of the question asked me a follow up question of which I answered, you do not want me to ignore the askers question because the title of the question may or may not be correct do you?
Also acunaara endorsed Fernando's first post
I do not assume anything from any question posted, I can not tell you how many times people have stated something in a title which was misleading or incorrect so I prefer to have the asker tell me I have misunderstood the question which has not happened but has asked me a follow up question.
Yes, i was looking this one:
^("Oracle[^\s]+)
Glad that worked out for you. Have a great day.