Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

remove all but folder name

Posted on 2011-02-18
13
311 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
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…

829 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