Cadet 3rd Class
Cadet 3rd Class
780 views

Parsing Issue with Escape Characters

Hello,

I have an override that inspects the message field and pulls out a filename and assigns it to deviceCustomString1.

eg.

submessage[0].pattern[0].regex = The file "([^"]+)" was accessed

...

My override works for most cases but breaks when the file directory string contains escape characters.

eg. msg=The file "C:\\windows\newfile" was accessed

the output in the logger would be

The file "C:\\windows

ewfile" was accessed

Where \n is treated as a new line escape character, and nothing parses properly.

Given that the [^"]+ statement does not include new line, I tried changing my regex to the following:

submessage[0].pattern[0].regex = The file "((?:\\n|[^"])+)" was accessed

This would not work. I also tried

submessage[0].pattern[0].regex = The file "((?:\n|[^"])+)" was accessed

and I also tried

submessage[0].pattern[0].regex = The file "((?:\\\n|[^"])+)" was accessed

None of these regex statements worked. Is there a simplier way to get the logger to ignore esscape characters in the message field? Perhaps a declaration of some kind at the beginning of the override?

 

Labels (3)
0 Likes
1 Reply
Lieutenant Commander
Lieutenant Commander

Hi,

 

For every "\" that you need to be escaped you need to add one more. So in your case if the regex you need to specify that you may encounter "\" and of course to be escaped (which means \\)

Differently the results may be unexpected.

A quick example in your case (C:\\windows\newfile") maybe will be:

regex=[C-D]:\\\\\\w+\\\\w+

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.