Java String.replaceAll regex

后端 未结 1 381
独厮守ぢ
独厮守ぢ 2021-01-02 07:55

What is the regex to strip the MY-CORP\\ part of na inputed string like MY-CORP\\My.Name with the java String.replaceAll method so I can get only the My.Name pa

1条回答
  •  -上瘾入骨i
    2021-01-02 08:23

    Your problem is that the backslash has special meaning both in Java strings and in regexes. So you need four slashes in the Java source code, passing two to the regex parser to get one literal one in the regex:

    return userWithDomain.replaceAll("^.*\\\\", "");
    

    0 讨论(0)
提交回复
热议问题