Jump to content

Recommended Posts

It seems so simple, but just cannot get this figured out..

 

In the following I'm trying to match the word "space" that does not contain numbers in the word before it..

 

161 space rd <-- no match

209 summit ave space 6 <-- match

 

Ultimately am trying to match (lot|unit|spc|space|ste|suite|bldg|building) that do not have numbers in the word before them..

 

Close example..

(if this contains a number, no match)\s(lot|unit|spc|space|ste|suite|bldg|building)

 

Thanks so much!

Edited by Scooby08
Link to comment
https://forums.phpfreaks.com/topic/271919-match-word-without-numbers-before-it/
Share on other sites

Normally the easiest solution is

(?<!...)

is a "negative lookbehind assertion", and forces the engine to only consider cases where that ... does not match. But its biggest drawback prevents its use here: it cannot be variable length. Like

(?<!(^|\s)\S+\d\S+)

 

So the next best thing: a non-capturing group.

(??<=^|\s)[^\s\d]+\d\S+)\s(lot|unit|spc|...)

 

[edit] Entirely numbers? Makes it easier.

(??<=^|\s)[^\s\d]+\s(lot|unit|spc|...)

Edited by requinix
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.