0

This is a follow-up of: javascript regex - look behind alternative?

In my situation, I'm looking to only match the second word when there is no specific word that preceeds the term. As with the prior issue I need a solution that doesn't utilize the look behind technique.

I'm looking to exclude mentions such as the following:

patient has a history of pulmonary edema

Using the expression:

((?!pulmonary ).{10})\bedema

But given the following sentence:

Continuing dyspnea and lower-extremity edema

I would like the match to only return edema instead of extremity edema.

Community
  • 1
  • 1
  • [What about this regex](https://regex101.com/r/hI1yZ8/2). Would that behave like expected? Match in group 1. – bobble bubble Feb 26 '16 at 19:11
  • Thanks for the quick reply. Apparently, regexpal and my javascript behave similarly and treat the entire line as a match in the last case "Continuing dyspnea and lower-extremity edema" – Sean Murphy Feb 26 '16 at 19:31
  • Did you [check/access the first group?](http://stackoverflow.com/questions/432493/how-do-you-access-the-matched-groups-in-a-javascript-regular-expression) See [JS fiddle](https://jsfiddle.net/1LL57c7h/) – bobble bubble Feb 26 '16 at 20:08

1 Answers1

1

Please try this pattern:

(?!pulmonary).{10}\b(edema)\b

The demo is here.

Quinn
  • 4,394
  • 2
  • 21
  • 19
  • I may not be asking this very clearly. I am matching `extremity edema`, but what I want to match is only `edema' in the following: _Continuing dyspnea and lower-extremity edema_ The criteria for excluding the term 'edema' has it's corresponding 9 character offset included (e.g. `123456789 edema`) but I want to drop the first word in what is returned as a pattern (e.g. no '123456789' included) – Sean Murphy Feb 26 '16 at 19:55
  • Apologies for the poor editing as my time limit ran out to fix. – Sean Murphy Feb 26 '16 at 20:01
  • The match it gives is only `edema`. (?!pulmonary) is a 'Negative Lookahead', not a ' look behind technique'. The 'look behind technique' looks like `(?<=...)` or `(?<!...)`. – Quinn Feb 26 '16 at 20:05
  • Agreed. As with the original poster had requested is that the method be an alternative to the 'look behind' technique. Apparently, javascript does allow the latter. – Sean Murphy Feb 26 '16 at 20:09
  • The limitation was only experienced in the Regexpal utility as `(?<!pulmonary).\b(edema)\b` worked perfectly fine in the code. Thanks again. – Sean Murphy Feb 26 '16 at 20:17
  • @SeanMurphy: Please take a look at [this pattern](https://regex101.com/r/hI1yZ8/5), which leaves out `1234567890 edema`. – Quinn Feb 26 '16 at 20:27