String parsing with triggers

triggers

#1

How do you parse values out of a string with triggers?

For example, User-Agent: Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 5.1; Trident/5.0)
What is best practice to parse for example MSIE 9.0 or Trident/5.0?


#2

Do you want to parse or simply match? It makes a difference. Parsing the UA string could be tricky because it changes so dramatically. If you want to simply check for the existence of the MISE 9.0 or Trident/5.0 strings, something like this will work for you:

var ua  = HTTP.userAgent;
if(ua && ua.indexOf("Trident") != -1){
// do something here, you've found a trident user agent...
}

I hope this helps. Another useful mechanism is the switch statement, although I find myself using the pattern above more often…