count \slash\" and cut after that --> reg expr."

  • 21 March 2015
  • 4 replies
  • 0 views

Badge +2

Hi All,

 

i have a question.

I want to count the slashes within a field and cut the Input Text after that.

I tried to use the "regular expression" action, but i dont know how to use the Regular Expression Language (I understood that the action uses the Microsoft .NET regular expression syntax).

 

e.g. input text

http://xxx.yyy.zz/aaa/bbb/123/456/567/allitems.aspx

 

in my case, i need the string "http://xxx.yyy.zz/aaa/bbb" (without the last slash)

 

Can anyone help me?

 

 

Greetings


4 replies

Userlevel 6
Badge +16

This could fit >>> http://[a-z./]+

You have some online tools for regular expressions. Here is one of them >>> RegExr: Learn, Build, & Test RegEx

Badge +6

Hi,

Your question is not fully clear to me. What do you mean by "counting"? Do you need the result of that count or the match that includes exactly that (or fewer) count of path fragments ending with slashes? For the latter you can use the {3} or the {3,5} syntax.

looks like you could use something like (?:(?:http|https|ftp|file)://|\{2}){1}([^/?#]+/){1,3}

Don't forget that URLs may start with other protocol schema monikers such as ftp, file, https, etc. Users might also use the UNC notation for network shares (\servershare).

You are right about the RegEx engine, and Fernando provided a link to a nice online tool to learn and test your expressions on varied inputs.

Badge +2

Hi Guys, thanks for your help.

I used the following and it works for my case perfect! http://[0-9a-z.]+/[[0-9a-z.]+/[0-9a-z.]+

Thank you

Greeting, Murat

Badge +6

I'm sure you understand that your regex is fragile, unless you've configured it to be case insensitive somehow wink.png rather than [a-z] I'd use w for "word" characters and d for digits.

Reply