code: public static String substituteContextPath(String htmlContent, String context) {
  
          if (m_contextSearch == null) {
              m_contextSearch = "([^\\w/])" + context;
              m_contextReplace = "$1" + CmsStringUtil.escapePattern(CmsStringUtil.MACRO_OPENCMS_CONTEXT) + "/";
          }
          return substitutePerl(htmlContent, m_contextSearch, m_contextReplace, "g");
      }
docs: Substitutes the OpenCms context path (e.g. /opencms/opencms/) in a HTML page with a
  special variable so that the content also runs if the context path of the server changes.<p>
  
  @param htmlContent the HTML to replace the context path in
  @param context the context path of the server
  
  @return the HTML with the replaced context path