Looking for a RegEx pattern

  • Thread starter Thread starter AWHK
  • Start date Start date
A

AWHK

I have some address string like this:

101st Street 45J
45th Karamba Street 123
1st Street 45L

I would like to use RegEx to extract any digits from the string as long as
they are not at the start of the string. I have a pattern like this
(?!^\d+)\d+ which works fine on '1st Street 45L' (captures 45 but not 1) as
it should. But in example '45th Karamba Street 123' it captures 5. What is
wrong?

I must say that I am not an expert on regular expressions...

Andreas :-)
 
Hi Andreas,

Based on the regex you have provided, I noticed that we have to use
negative lookbehind instead of negative lookahead. You can try to use the
following pattern. It works fine on my machine.

(?<!^\d*)\d+

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help with Regex 1
regex help 1
Regex in C# 4
Splitting up address 3
Regex Pattern 11
escaping double quotes in Regex 3
regex pattern 4
Regex Help 2

Back
Top