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.

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.