Solved

remove all but folder name

Posted on 2011-02-18
13
309 Views
Last Modified: 2012-08-14
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
Comment
Question by:metatonka
  • 5
  • 5
  • 3
13 Comments
 

Author Comment

by:metatonka
ID: 34926887
Microsoft .NET regular expression syntax is used in this application
0
 

Author Comment

by:metatonka
ID: 34926985
this
[^/]+(?=/[^/]+$)
resulted in
Bartow;
need to get rid of the ";"
0
 
LVL 6

Expert Comment

by:t-max
ID: 34927667
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:metatonka
ID: 34928442
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34928489
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34928503
*school names    : )
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34928524
Actually, a slight tweak:
[^/]+?(?=[\W/]*/[^/]+$)

Open in new window

0
 

Author Comment

by:metatonka
ID: 34929117
thank you, but the result of
 [^/]+?(?=[\W/]*/[^/]+$) was blank

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 125 total points
ID: 34929494
That's a "w" (double-u), not a series of slashes ; )
0
 
LVL 6

Expert Comment

by:t-max
ID: 34929515
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34929531
NM. My font is screwy in this browser...   : \

Please show how you've implemented the pattern. Here's what I get:
untitled.png
0
 
LVL 6

Assisted Solution

by:t-max
t-max earned 125 total points
ID: 34929540
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
 

Author Closing Comment

by:metatonka
ID: 35264282
thanks
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question