Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

remove all but folder name

first, i am a just learning regular expressions. so thank you for your help.

1) have 55 folder names of schools
2) workflow that starts and then i captures the url
http://acorn2/principals/Principal%20Reports/Students%20Records%20AYP/Bartow/sdfsdfsdfsf.txt
3) the folder name in this example will be bartow
4) want to capture the folder name from the url and save it as a workflow variable. and i know how to do this.

so what regular express string could i use to remove all other text in the url and then is left with the school folder name.

thank you very much.
0
metatonka
Asked:
metatonka
  • 5
  • 5
  • 3
2 Solutions
 
metatonkaAuthor Commented:
Microsoft .NET regular expression syntax is used in this application
0
 
metatonkaAuthor Commented:
this
[^/]+(?=/[^/]+$)
resulted in
Bartow;
need to get rid of the ";"
0
 
t-maxCommented:
Want to try this?
.+/([a-zA-Z0-9]+)/.+$

Open in new window

It means (in theory): match the last string found in the url, with at least 1 character (letters and/or numbers), which is surrounded by "/", and that has non-empty strings of any characters before and after it.
The regex can be much more specific if needed, but it should do what you want.

BTW, isn't clear where that ";" came from, as it didn't appear in the url, nor it's mentioned in your regex.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
metatonkaAuthor Commented:
i know, i do not know where the ";" comes from.
darn...i tried your regex
got this:
http://acorn2/principals/Principal%20Reports/Students%20Records%20AYP/Bartlett/sdfsdfsdfsf.txt;
duplication of the line WITH ";"
they say they are Microsoft .NET regular expression syntax
any other thoughts?
0
 
käµfm³d 👽Commented:
You'll need to have a clear picture of the kinds of strings you'll be receiving. t-max's pattern is sufficient for city names without spaces, but if you do get a city name with a space, and the space is URL-encoded, then the pattern will fail.

We can modify your original pattern a bit:
[^/]+(?=[\W/]*/[^/]+$)

Open in new window

0
 
käµfm³d 👽Commented:
*school names    : )
0
 
käµfm³d 👽Commented:
Actually, a slight tweak:
[^/]+?(?=[\W/]*/[^/]+$)

Open in new window

0
 
metatonkaAuthor Commented:
thank you, but the result of
 [^/]+?(?=[\W/]*/[^/]+$) was blank

0
 
käµfm³d 👽Commented:
That's a "w" (double-u), not a series of slashes ; )
0
 
t-maxCommented:
I just tried your url and my regex in http://regexlib.com/RETester.aspx and it worked without problems.
The matched parttern is stored in the variable $1.
To give it a try, go to the site above, paste the url under "Source":
http://acorn2/principals/Principal%20Reports/Students%20Records%20AYP/Bartlett/sdfsdfsdfsf.txt

Open in new window

And my regex below (slightly modified to allow spaces and other url encoded characters) in "Regular Expression":
.+/([a-zA-Z0-9%]+)/.+$

Open in new window

Then hit "Submit", and move the scroll bard to the right to see the value of $1.
0
 
käµfm³d 👽Commented:
NM. My font is screwy in this browser...   : \

Please show how you've implemented the pattern. Here's what I get:
untitled.png
0
 
t-maxCommented:
BTW, this is a nice link to start understanding .NET regex:
http://www.radsoftware.com.au/articles/regexlearnsyntax.aspx
http://www.radsoftware.com.au/articles/regexsyntaxadvanced.aspx
Hope the above sheds some light on this matter.
0
 
metatonkaAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now