RegEx删除GTM Param

时间:2015-05-21 21:20:23

标签: jquery regex

用""替换整个字符串?_ga =和随机cookie的正则表达式是什么?空字符串所以结果将是www.example.com而不是example.com /?_ ga = 1.263876746.721545158.1431088909

此示例仅针对?_ga =并且仅是用于模拟问题的演示:



    $("a").click(function (e) {
        $(this).attr("href", "?_ga=1.263876746.721545158.1431088909"); 
      var value = $(this).attr('href');
      $(this).attr('href', value.replace('?_ga=', ''));
        e.preventDefault();
            alert(this);
    });

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<a href="http://example.com/">Link 1</a>
<a href="http://example.com/">Link 2</a>
&#13;
&#13;
&#13;

演示:http://jsfiddle.net/aj948wv4/

2 个答案:

答案 0 :(得分:1)

你可以试试这个正则表达式

import java.awt.*; import java.util.*; import javax.swing.*; import javax.swing.table.*; public class SSCCE extends JPanel { public SSCCE() { setLayout( new BorderLayout() ); JTable table = new JTable(5, 5); table.setOpaque( false ); DefaultTableCellRenderer renderer = (DefaultTableCellRenderer)table.getDefaultRenderer(Object.class); renderer.setOpaque(false); JScrollPane scrollPane = new JScrollPane( table ); scrollPane.setOpaque( false ); scrollPane.getViewport().setOpaque( false ); final ImageIcon icon = new ImageIcon("mong.jpg"); JPanel background = new JPanel( new BorderLayout() ) { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(icon.getImage(), 0, 0, getWidth(), getHeight(), this); } }; background.add( scrollPane ); add(background); } private static void createAndShowGUI() { JPanel panel = new JPanel(); JFrame frame = new JFrame("SSCCE"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new SSCCE()); frame.setLocationByPlatform( true ); frame.pack(); frame.setVisible( true ); } public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }

Working Demo

答案 1 :(得分:0)

此解决方案比正则表达式更能满足我的需求

    var value = $(this).attr('href');
    $(this).attr('href', value.split('?_ga=')[0]);

演示:http://jsfiddle.net/aj948wv4/2/