Extract a reference number from an email

andrewdunn
Giga Expert

Team - I have read a lot on the forums about inbound actions but I am unable to get the following working for me. Any assistance greatly appreciated:

Inbound email subject along the line of:

[REF #1234] Create ticket for outage

Requirement:

Remove REF #1234 from between [ ] and place in a field called u_vendor_reference

Actions tried but not working:

current.u_vendor_reference = email.subject.match(/^[ (.+)$/]);

My understanding is that with the above /^ should signify the beginning of the text to be extracted

$/ should signify the end

and everything between should be extracted and placed in current.u_vendor_reference

Is my thinking to simplistic? Currently on Eureka

Cheers

1 ACCEPTED SOLUTION

russell_miller
Kilo Guru

Hi Andrew,



Have   you tried this?



      var subjMatch = new RegExp("(\[REF #[0-9]*)\]","g");


      var subjectExtRef = email.subject.match(subjMatch).toString();



Should get you the whole thing and then you could remove the [ and the ].



This online tool is handy for RegEx:



RegExr: Learn, Build, & Test RegEx



Hope that helps


View solution in original post

3 REPLIES 3

russell_miller
Kilo Guru

Hi Andrew,



Have   you tried this?



      var subjMatch = new RegExp("(\[REF #[0-9]*)\]","g");


      var subjectExtRef = email.subject.match(subjMatch).toString();



Should get you the whole thing and then you could remove the [ and the ].



This online tool is handy for RegEx:



RegExr: Learn, Build, & Test RegEx



Hope that helps


Abhinay Erra
Giga Sage

Andrew,



As russell mentioned email.subject.match(/\[REF #[0-9]*\]/g) will give you the reference number and then you can remove the braces by using this


var refArr= email.subject.match(/\[REF #[0-9]*\]/g);


var ref=refArr[0].substring(1,(refArr[0].length-1));


variable ref will give you the desired value.




Thanks,


Abhinay



Please mark Helpful, Like, or Correct depending on the impact of the response


andrewdunn
Giga Expert

Thanks for the information - needed to make a few slight changes to the code but these ideas sent me in the right direction and got me 99% of the way there


Much appreciated


Cheers