[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

How do I add/replace Google Analytics code using regular expression?

Google Analytics code contains special symbol such as quotation and semicolon marks.

I'm using Perl to dynamically update and replace certain content of my html template to generate static page.  For specific purpose, I can't simply just add the tracking code to the html page.

I would like to use regular expression to match for </head>

and then append the Google Analytics code before the closing </head>

How can this be done?
1 Solution
Assume var $google has the analytics

Try a replace:

$html =~ s/</head>/$google<\/head>/s;

jay28leeAuthor Commented:
how do i assign a piece of code to a variable with special symbol of quotation and semicolon marks?

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now