
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 01:27 PM
I'm struggeling with some RegEx to filter out values from a text-file. RegEx is used in a custom pattern I've created, but I can't get it to match in the pattern.
I've tried it on RegEx101 but I can't get it to match in the pattern.. Anyone here that can give me some examples of what might work?
The file will have two lines. The first with headers and the second one with data.
I'm looking for matching on the second row only. See screendump of what values I want to catch:
Text in file:
HOST_NAME#DB_NAME#INSTANCE_NAME#DB_STATUS#STANDBY_HOST_NAME#dbversion#db_size_gb#dg_status#is_rac#partition_used
my1#my2#my3#my4#my5#my6#my7#my8#my9#my10
RegEx Used to match:
\n.+?\#.+?\#(.+)?\#.+?\#.+?\#(.+)?\#(.+)?\#(.+)?\#(.+)?\#(.+)?
But using the same RegEx in my Pattern does not work. It's not matching:
But I have this below RegEx and this one works but only on the first row, and that row is only for headers:
.+?\#.+?\#(.+?)\#.+?\#.+?\#(.+?)\#(.+?)\#(.+?)\#(.+?)\#(.+)
I have tried to add "\n" in the start of the RegEx but then it does not work anymore in ServiceNow pattern.
Anyone here who can figure out what I should do to make it work?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2022 03:10 AM
Found a better regex to fit my needs, but I also managed to change the output of the file and not look on the second line anymore. Not the desired fix, but it did the job and therefore I'm closing the post based on this.
RegEx used instead:
.*?\#.*?\#(.*?)\#.*?\#.*?\#(.*?)\#(.*?)\#(.*?)\#(.*?)\#(.*)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 01:45 PM
Hi,
I am not sure if you can do th evalidaiton on the entire file when you just want it to run it for 2nd line. I would rather read the file content, skip the 1st line, then run the validation.
Hope that helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 01:50 PM
Hi
The file will never* be more then the two lines, so that was my idea to use RegEx then. But you may have a point here that this is won't work at all.
Hope to have some more feedback from all you great users in the forum!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 01:55 PM
I am not so good with regex, but i know that in regex you can also do the validation from the backwards of the string. so may be try your condition to check form the back instead of the start and see.
But then still you need to separate the content from header to actual content, which means you need to read it first.
Mark the comment as a correct answer or helpful if this helps to solve the problem.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 02:31 PM
This seem to match on correct points in text and/but does so on all lines. Maby I can use this in the array in a later step to just get the second value in the array?
.*?\#.*?\#(.*?)\#.*?\#.*?\#(.*?)\#(.*?)\#(.*?)\#(.*?)\#(.*)