Syntax used in a match method
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2015 04:08 AM
I need to amend the code in a Business Rule. Variables are being assigned values by using the Match method but I don't understand exactly what the search rules are, and have not been able to find similar examples. These are the lines in the code. Is anyone able to explain exactly what is being searched for and/or point me to some online help.
var task_ref = current.payload.match(/ITASK[0-9]{7}/);
I believe the 2 forward slashes show the start and end of the match criteria.
I think the above match is looking first for a string 'ITASK', followed by 7 numeric characters.
var fw_ref = current.payload.match(/IR.*?(?=\])/i);
I understand the final 'i' indicates that the search is case insensitive.
I presume it is looking for a string starting with 'IR' but I don't understand the rest.
var fw_ref1 = current.payload.match(/;IR.*?(?=&)/i);
Similarly, I don't know what this means.
This is my first post so let me know if I need to do it differently in any way.
Many thanks
Ruth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2015 11:28 AM
Hi Ruth,
The syntax used in the javascript match method is known as a regular expression, also known as regex.
Some resources around regex:
W3 Schools article: JavaScript String match()Method
Regex Tester and Debugger Online - Javascript, PCRE, PHP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2015 01:13 AM
Thanks Michael, I have got it now, your 2nd link explained it all. There seems to be some problem on my laptop for using the Tester and Debugger but I am pretty sure it is to do with my organisation's laptop build, I'll get that sorted.