Solved

remove all but folder name

Posted on 2011-02-18
13
307 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
 

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 74

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 74

Expert Comment

by:käµfm³d 👽
ID: 34928503
*school names    : )
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 74

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 74

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 74

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
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…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now