string replace using regular expression

I would like to remove ISC header info before the error message. Hence I am using string replace using regular expression.

[ISC.0082.9034] Field is absent, field must exist.

The regular expression I am using in search field is /^[ISC/… But I am getting the below error.

org.apache.oro.text.regex.MalformedPatternException: Unmatched [] in expression.
I know there are other solutions. But Just want to know what am I doing wrong in this case.

Thanks
Srinivas

The [ has special meaning in regex. If you want to use it literally, escape it.

/^[ISC.*] /

assuming that there are no other closing square brackets with a following space in your string.

Chris
My inputs for string.replace service are
inString---->[ISC.0082.9034] Field is absent, field must exist
searchString----->/^[ISC.*] /
replaceString----->X
useRegex----> true

My output value is still the same

[ISC.0082.9034] Field is absent, field must exist. So can you let me know if I am missing something.

I am expecting X Field is absent, field must exist for the output value.

Thanks for your help.
Srinivas

Remove the enclosing slashes.

My inputs for string.replace service are
inString---->[ISC.0082.9034] Field is absent, field must exist
searchString----->^[ISC.*]
replaceString----->X
useRegex----> true

Hi Srinivas,

I’m not sure we can use regular expressions in replace function to define a boundary and replace them with a single char but if your requirement is to just delete the error code from the error message then this is my suggestion: Form a regular expression which would pattern match numberics(0-9) and ‘.’ which would start with [ISC and end with ‘]’ and and leave the replaceString empty. This would remove the error code.

BUT BEWARE that this would remove any other numbers and . in the whole message.

Another way you can do is to do a 3 step.

[INDENT]1. indexOf("]")
2. substring(0,index)
3. replace(substring,replaceString="")
[/INDENT]
Hope this helps.

-Suren

Hi,

If you will use Search String as ^[ISC.*] it will work fine.

cheers!
nD

To elaborate, the surrounding slashes on a regex are only needed when regex is used as a label in a branch step. Other facilities that support regex do not need them.

Thanks Guys, It worked with your inputs.