The regular expression in TCL:
The regexp command has as syntax:
regexp ?switches? exp string ?matchVar? ?subMatchVar1? ?subMatchVar2? ...?
The character ? say that the parameter is optional. where :
Example made with OWB - OMB (Oracle Meta Base) Language
OMB+> regexp {PREFIX_(.*)_POSTFIX} "PREFIX_TO_FIND_POSTFIX" matched sub1 sub2 sub3
1
# return 1 to indicate that a match was found
OMB+> puts $matched
PREFIX_TO_FIND_POSTFIX
# Return the matched string
OMB+> puts $sub1
TO_FIND
# return the string that match for the parenthese
Perform substitutions based on regular expression pattern matching.
regsub ?switches? exp string subSpec ?varName?
This command matches the regular expression exp against string, replace the match with subSpec and either copies string to the variable whose name is given by varName or returns string if varName is not present.
Switches: If the initial arguments to regsub start with - then they are treated as switches. :
OMB+> set a "string_with_part_to_suppress"
string_with_part_to_suppress
OMB+> regsub {with_part_to_suppress} $a "" a
1
OMB+> puts $a
string_
Below a method to suppress the curly brace that are use by tcl to escape special characters. When you use the OMB language of OWB, you can get as return value this double curly brace “{}” that indicates that you have no values.
proc P_SuppressCurly Vs_StringWithCurly {
# Suppress all curly
regsub -all "({|})" $Vs_StringWithCurly "" Vs_StringWithoutCurly
return $Vs_StringWithoutCurly
}
OMB+> set Vs_OriginalString "Start_ToReplace_End"
Start_ToReplace_End
OMB+> set Vs_StringToReplace "ToReplace"
ToReplace
OMB+> set Vs_StringToPut "IsReplaced"
IsReplaced
OMB+> regsub $Vs_StringToReplace $Vs_OriginalString $Vs_StringToPut Vs_OutputString
1
OMB+> puts $Vs_OutputString
Start_IsReplaced_End