1

i have to extract id value of a product from url.

It is SEO Friendly (url routing).

Url can be

http://www.example.com/{param0}/{param1}/123/{param2}/{paramN}

Or

http://localhost:6847/{param0}/{param1}/123/{param2}/{paramN}

For the first url there is no problem. But for the second i want to extract ONLY the 123 or (ID) <-(It is an Integer).

I know that if i want to extract only numbers i can use

[0-9]+

but how can i tell regengine how to get all the numerical data from url except numbers that may have

:

before. i use :

((!:)[0-9]+) 

it is not correct. Every advice is wellcamed:)

Thank you.

1 Answer 1

1

There needs to be more info on what delimits the 123 in your example.

On its face, (?<!:)[0-9]+ will find the first clump of digits NOT preceded by ':'

Edit Probably for more accuracy, this (?<!:\d+)[0-9]+ would be better.
Note this is if .NET allows variable length look-behind (I think it does).

For fixed length look-behind (PCRE), something like this might work: (?<![:\d])[0-9]+

Edit2

@Sanosay- After thinking about .NET type lookbehinds, the above regex needs a slight change. It should be (?<!:\d*)[0-9]+ . Thats because in ':1234', 1 will satisfy the assertion.

Hope you figured this to be the case. I made a test case for the two regex's
@"(?<!:\d*)[0-9]+"
@"(?<![:\d])[0-9]+"
that satisfy the conditions.

The link to the ideone C# code is here: http://ideone.com/tLn2j

Sign up to request clarification or add additional context in comments.

2 Comments

The 123 is for example an ID of a product (only int). I will test your solution..i think that it will work:)
:/ It is not working. (i think i have test that solution before). Ouput for localhost:14964/rToz/product/311/Testing : 4964

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.