wetware05 wrote: ↑01 Jan 2023, 06:32
he just wants to delete the symbols ()
My understanding was that they wanted to remove parenthesis and contents within, if the contents are time. If they just wanted to remove the parenthesis surrounding time, then below are a couple ways. These are just possibilities - I'm sure there are other ways, that the "true experts" could present.
In this case we take advantage of a capture group to remove the entire match, then put just the contents (time) back using the $1 on-the-fly "variable".
Code: Select all
; specific - am/pm is optional, to allow for military time as well
clipboard := RegExReplace(clipboard, "i)\h*\((?:at)?\h*(\d{1,2}(?:\.|:)\d{2}\h*(?:AM|PM)*)\)", " $1")
; OR
; less specific, using just AM or PM as match factor for time (am/pm no longer optional)
; NOTE - the less specific version can cause false-positives
; for instance it would also remove parenthesis from (spam)
clipboard := RegExReplace(clipboard, "i)\h*\(([^\)]+(?:AM|PM))\)", " $1") ; explanation below
/*
i) case-insensitive (for am/pm or AM/PM)
\h* optional horz whitespaces
\( left/opening parenthesis
( begin capture group 1
[^\)]+ anything (+ means mandatory - 1 or more chars) that is NOT a right/closing parenthesis...
(?:AM|PM) ... up to and including AM or PM (am/pm also mandatory - no longer optional)
) close capture group 1
\) right/close parenthesis
" $1" replace with a space and what was captured in group1 (essentially just removing parenthesis from match)
*/