正则表达式:拆分为路径

时间:2015-11-05 22:57:23

标签: c++ regex path filepath unc

我想拆分主机名,共享文件夹,路径,文件名和扩展名的UNC路径。我几乎得到了它,但最后一个序列是错误的,因为我没有正确得到文件。

e.g。

//host/shared/path1/path2/path3/filename.pdf

应分为:

host
shared
path1/path2/path3
filename
pdf

但此刻我得到了类似的东西:

host
shared
path1/path2/path3/filenam
e
pdf

使用此正则表达式:

std::regex rgx("\/\/(\\w+?){1,1}\/(\\w+?)\/([\\w\/]+)([^\\.])\\.(.+)$");

那么它有什么问题,我该如何解决呢?

1 个答案:

答案 0 :(得分:2)

您要删除群组"([^ \\。])"如下所示" \\。"匹配最后的句号。您还希望另一个单词组与文件名本身匹配,后跟句点,如下所示:

<head>
		<link href='https://fonts.googleapis.com/css?family=Exo:200' rel='stylesheet' type='text/css'>
		<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  		<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width">
	</head>
<div class="container-fluid back-image screen">
		<div class="circle-button-large circle-large-center"></div>
		  <div class="orbit-text-container">
			  <div class="text-center text-medium-large circle-text-top orbit-text"><a href="text1.html">Text1</a></div>
			  <div class="text-center text-medium-large circle-text-bottom orbit-text"><a href="text2.html">Text2</a></div>
			  <div class="text-center text-medium-large circle-text-left orbit-text"><a href="text3.html">Text3</a></div>
			  <div class="text-center text-medium-large circle-text-right orbit-text"><a href="text4.html">Text4</a></div>
		  </div>
		</div>

https://regex101.com/r/yK4zH1/4