1

I looked and the closest answer I got was capturing filename from url without extension

So I have this cshtml:

<script src="@Url.Content("~/Scripts/javascript.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/javascript2.js")" type="text/javascript"></script>

i tried using this regex:

(?!.+[Ss]cripts+\/)\/+.+\.js

However, using Rad regex designer i am getting this result

  • /javascript.js
  • /javascript2.js

how can I capture just this

  • javascript (without .js)
  • javascript2 (without .js)

I will then use a replace expression

$&.min.

to come out with the final result

<script src="@Url.Content("~/Scripts/javascript2.min.js")" type="text/javascript"></script>

thanks in advance for the help.

Community
  • 1
  • 1
bherto39
  • 1,516
  • 3
  • 14
  • 29

2 Answers2

0

Adding a capturing group should accomplish what you want:

((?!.+[Ss]cripts+\/)\/+.+)\.js

This will still include the / at the beginning, but that should be okay.

Jordan Kaye
  • 2,837
  • 15
  • 15
0

just want to add the following combination worked:

so i have a cshtml file with some script tags like this:

<script src="@Url.Content("~/Scripts/javascript.js")" type="text/javascript"></script>

then i used regex replace using MSbuild target as:

<MSBuild.ExtensionPack.FileSystem.File TaskAction="Replace" RegexPattern="((?!.+[Ss]cripts+\/)\/+.+)\.js" Replacement="$1.min.js" Files="@(CSHTML)" />

right then and there the replacement expression $1.min.js

resulted to replace the

<script src="@Url.Content("~/Scripts/javascript.min.js")" type="text/javascript"></script>
bherto39
  • 1,516
  • 3
  • 14
  • 29