Help with positive lookbehind and more REGEX

Below is just an example.

City Code NY-4123
Postal Number: 4235126

To get the City Code I am currently using this regex:

(?<=City Code)(.+)

Output: “NY-4123”

Sometimes it can look like this

City code:NY-4123
Postal Number: 4235126

How to handle lower and upper case letters and if suddenly “:” is present. I dont want the output to be

“: NY-4123”

And the last variant(misspelling(Nuber)):

City code:NY-4123
Postal Nuber: 4235126

How do I make a regex that gives me the Postal Number only and that can handle misspellings?

Hi,

Try like below regex expression. Please try and let us know. Thanks.

(?i)(?<=City Code)\s:(.+)

(?i) → ignore case

Keep one backslash for this : symbol some how i am not able to type using my mobile.

Hi @atomic

Try out this regex it can capture both the scenarios you mentioned above

((?<=City Code:)|(?<=City Code ))(.+)

Thanks,

For this you can simply use the below one,

image

If Postal code is fixed one (Example 7 digits), then below one as well,

image

Alternative way,
image

For City code you can use what @Robinnavinraj_S /@kirankumar.mahanthi1 is mentioned.

Hope this one will be helpful. Thank you.

Hi,

Can you try the following expression? Theses output correct value from all the above 3 samples and can handle some patterns of misspelling.

cityCode = System.Text.RegularExpressions.Regex.Match(yourString,"(?<=City\W+\w+\W+)\w.*",System.Text.RegularExpressions.RegexOptions.IgnoreCase).Value

postalNumber = System.Text.RegularExpressions.Regex.Match(yourString,"(?<=Postal\W+\w+\W+)\w.*",System.Text.RegularExpressions.RegexOptions.IgnoreCase).Value

Regards,