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."
 
Back
Top