- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 02:16 AM
Hi,
I have been searching the community but not actually found the solution. I need to extract the text between the the 2 "|" as shown in the below example:-
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 02:20 AM
Hello @jonathangilbert ,
Try below script
var input = "TICKET ID 924209 | ABNORMAL_ANONYMOUS_IP | JOE BLOGGS";
var parts = input.split("|");
var result = parts.length > 1 ? parts[1].trim() : "";
gs.info("Extracted value: " + result);
and below is the updated script of yours,
var str = 'TICKET ID 924209 | ABNORMAL_ANONYMOUS_IP | JOE BLOGGS';
var split1 = str.split(";");
var cat = parts.length > 1 ? parts[1].trim() : "";
current.u_report_name = cat;
Thanks,
Valmik Patil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 02:20 AM
Hello @jonathangilbert
Use below 👇 regex pattern
const text = "TICKET ID 924209 | ABNORMAL_ANONYMOUS_IP | JOE BLOGGS";
const match = text.match(/\|([^|]+)\|/);
if (match) {
const extractedText = match[1].replace(/_/g, ' ');
console.log(extractedText); // Output: "ABNORMAL ANONYMOUS IP"
}
I hope this answered your query.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 02:20 AM
Hello @jonathangilbert ,
Try below script
var input = "TICKET ID 924209 | ABNORMAL_ANONYMOUS_IP | JOE BLOGGS";
var parts = input.split("|");
var result = parts.length > 1 ? parts[1].trim() : "";
gs.info("Extracted value: " + result);
and below is the updated script of yours,
var str = 'TICKET ID 924209 | ABNORMAL_ANONYMOUS_IP | JOE BLOGGS';
var split1 = str.split(";");
var cat = parts.length > 1 ? parts[1].trim() : "";
current.u_report_name = cat;
Thanks,
Valmik Patil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 02:27 AM
Morning Valmik,
Thanks for that it works perfectly and thanks for the quick response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 02:29 AM
Hello @jonathangilbert
Did you try my solution ? Did it not working for you ?
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY