0
(?<=\AL|AL|AK|Alaska|AZ|Arizona|AR|Arkansas|CA|California|CO|Colorado|CT|Connecticut|DE|Delaware|DC|District of Columbia|FL|Florida|GA|Georgia|HI|Hawaii|ID|Idaho|IL|Illinois|IN|Indiana|IA|Iowa|KS|Kansas|KY|Kentucky|LA|Louisiana|ME|Maine|MD|Maryland|MA|Massachusetts|MI|Michigan|MN|Minnesota|MS|Mississippi|MO|Missouri|MT|Montana|NE|Nebraska|NV|Nevada|NH|New Hampshire|NJ|New Jersey|NM|New Mexico|NY|New York|NC|North Carolina|ND|North Dakota|OH|Ohio|OK|Oklahoma|OR|Oregon|PA|Pennsylvania|RI|Rhode Island|SC|South Carolina|SD|South Dakota|TN|Tennessee|TX|Texas|UT|Utah|VT|Vermont|VA|Virginia|WA|Washington|WV|West Virginia|WI|Wisconsin|WY|Wyoming)[\s+]+(\d{5})

In my regex I am collecting 5 digit zipcodes that have a preceding state abbreviation in front of it. What I have happening is it's collecting a string of numbers that I don't want it pulling because it has ID at the end of the word so it's thinking it's Idaho. ex. "Registry Caller ID 98745". I want to exclude anything that is behind this string "Registry Caller ID" How do I add it to this so it will do that?

Second question, I have a space in front of my zipcode how do I remove that single space?

Zoe
  • 27,060
  • 21
  • 118
  • 148
  • 1
    Any reason for the lookbehind? Why not just using a *non capturing group* and if you only want to match after the full words, put a *word boundary* at the start [like this](https://regex101.com/r/x1hP7L/1). – bobble bubble Jul 12 '22 at 18:45
  • Because I want it to find the zipcode and not the state abbreviation in front of it. I'm using the State abbreviation as way to find the zipcodes, sort of as an anchor. – Monsterandroid Jul 12 '22 at 18:53
  • 1
    Then use a capture group? As in `\bA[LKZR]\s*(\d{5})`....with the obvious that I didn't include all your options... – JvdV Jul 12 '22 at 18:56
  • Sidenote: With [`\AL`](https://regex101.com/r/wFHjC2/1) you want to match an `L` at string start? Just to mention it... – bobble bubble Jul 12 '22 at 19:00
  • Yes, I noticed that afterwards :D The text I copied was a little out of date. – Monsterandroid Jul 12 '22 at 19:06
  • Update, in the E-mail I am searching in it is Caller ID, not CallerID so it's assuming its Idaho. Caller and ID are separate. So that kind of changes things. – Monsterandroid Jul 12 '22 at 19:08
  • @Monsterandroid Just use a neg. lookbehind before the `ID` maybe [like this](https://regex101.com/r/vkwWe1/1). To get rid of the space if you're using PCRE (PHP) e.g. like [that demo](https://regex101.com/r/fNYcd9/1) by use of `\K` (without capture group) (always helpful if you mention tool/lang you're using). – bobble bubble Jul 12 '22 at 21:44
  • 1
    @bobblebubble - Thanks for the advice and update, I was just using Regular Expressions with UIPATH, not sure what UIPATH uses. I'm still in the process of learning a lot of coding stuff, so I really appreciate your time in explaining this. – Monsterandroid Jul 13 '22 at 13:17

0 Answers0