Jump to content

Match Word Without Numbers Before It


Scooby08

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!

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|...)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.