简体   繁体   English

正则表达式精确匹配字符串

[英]Regex to match a string exactly

I have the following string: 我有以下字符串:

E:\Confluence_Attachments\ver003\10\85\1835010\124\165\4915874\19169322\1

How do I get the substring that begins with ver003? 如何获得以ver003开头的子字符串?

I want only this part of the string: 我只需要字符串的这一部分:

ver003\10\85\1835010\124\165\4915874\19169322\1

If I understand your question, you can use .+ and group the desired elements with () and then use a replaceAll like 如果我理解您的问题,则可以使用.+并将所需元素与()分组,然后使用replaceAll这样

String s = "E:\\Confluence_Attachments\\ver003\\10\\85\\"
        + "1835010\\124\\165\\4915874\\19169322\\1";
System.out.println(s.replaceAll(".+(ver003.+)", "$1"));

Which outputs (as requested) 哪些输出(根据要求)

ver003\10\85\1835010\124\165\4915874\19169322\1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM