Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Parse OTRS subject for TicketNumber and Title in JavaScript
function SubjectParse ( Subject, Hook ) {
var Data = {};
var SubjectRegExp = new RegExp( '^'+ Hook + '(\\d+)\\s*(?:-|–)\\s*(.+)$','');
var Match = SubjectRegExp.exec(Subject);
if ( Match && Match.length ) {
Data['Subject'] = Match[0];
Data['TicketNumber'] = Match[1];
Data['Title'] = Match[2];
}
return Data;
}
var Result = SubjectParse( 'Ticket#20141210330000038 - TEST', 'Ticket#' );
console.log(Result);
// Subject: "Ticket#20141210330000038 - TEST"
// TicketNumber: "20141210330000038"
// Title: "TEST"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.