Scooby08 Posted December 12, 2012 Share Posted December 12, 2012 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 More sharing options...
Scooby08 Posted December 12, 2012 Author Share Posted December 12, 2012 I'm sorry, the example I sent should be like so: (if this contains all numbers (civic#), no match)\s(lot|unit|spc|space|ste|suite|bldg|building) Thanks.. Link to comment https://forums.phpfreaks.com/topic/271919-match-word-without-numbers-before-it/#findComment-1398964 Share on other sites More sharing options...
requinix Posted December 12, 2012 Share Posted December 12, 2012 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|...) Link to comment https://forums.phpfreaks.com/topic/271919-match-word-without-numbers-before-it/#findComment-1398967 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.