Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

remove all but folder name

Posted on 2011-02-18
13
Medium Priority
?
317 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
[X]
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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 500 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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
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…
Suggested Courses

704 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