替换特定URL参数中的字符

我正在尝试将/的URL param1参数值中的\替换为param2,但是我想不出如何更改所有参数就不能做到这一点像param1=abc/def/123&param2=abc/def/123

例如

param1=abc\def\123&param2=abc/def/123

我想成为

  public static void main(String[] args) {
    int[][] arr = new int[3][3];
    printArray(arr);
    printArray(arr,true);
  }

  // method to print the loaded array
  public static void printArray(int[][] arr) {
    printArray(arr,false);
  }

  // method to print the sorted array
  public static void printArray(int[][] arr,boolean sort) {
    System.out.println("Loaded and Sorted Array \n");
    for (int i = 0; i < arr.length; i++) {
      if (sort) {
        Arrays.sort(arr[i]);
      }
      for (int j = 0; j < arr[i].length; j++) {
        System.out.print(arr[i][j] + " ");
      }
      System.out.println();
    }
  }

这里是regex101 example

szchengw 回答:替换特定URL参数中的字符

我将其分为两个简单步骤。首先用正则表达式找出“ param1 = ...”子字符串,然后在其中将“ /”替换为“ \”。这是JavaScript中的示例:

var str = "param1=qwe/qwe/wer&param2=qd/fs/aw";
var match = str.match(/^(.*)(param1=[a-z\/0-9_]+\b)(.*)$/);
var result = match[1] + match[2].replace(/\//g,"\\") + match[3];
console.log(str,result);

本文链接:https://www.f2er.com/3149299.html

大家都在问