Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to use regular expression to get all the characters from a line until a specific character occurs.
For example, I have the following line:
context-root1/*.jsv"/>
I want to be able to just extract the word context-root1
(in other words, I want to be able to extract all the characters before the /). I am trying to do this in a batch file. The code I have so far which is relevnt for this is as follows:
set finalvar=!myvar:~7,100!
echo !finalvar!
where the first line is looking at the string:
<Uri AffinityCookie="JSESSIONID" AffinityURLIdentifier="jsessionid" Name="/contextroot1/*"/>
and getting the string:
contextroot1/*"/>I need to be able to make it just get the string contextroot1. So in other words get all the words before the first / occurs.
I know that this would be possible with regular expressions, but not sure how it can be done.
I know this should be easily done with regular expresions, but I do not have a lot of experience with them.

you can use vbscript
Set objFS = CreateObject("Scripting.FileSystemObject") strFile = "c:\test\file.txt" Set objFile = objFS.OpenTextFile(strFile) Do Until objFile.AtEndOfStream strLine = objFile.ReadLine If InStr(strLine,"AffinityCookie") > 0 Then s = Split(strLine,"Name="&""""&"/") ind = InStr(s(1),"/") WScript.Echo Mid(s(1),1,ind-1) End If Loop objFile.Closeon command line
C:\test>more file.txt <Uri AffinityCookie="JSESSIONID" AffinityURLIdentifier="jsessionid" Name="/contextroot1/*"/> C:\test>cscript /nologo test.vbs contextroot1

@echo off > newfile & setLocal EnableDelayedExpansion
set str=context-root1/*.jsv"/>
for /f "tokens=1 delims=/" %%a in ("!str!") do (
set newstr=%%a
)echo !newstr!
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |