Jump to content

Some more regex help (Solved)


Recommended Posts

I have  lines of data:

Example:  Encounter Info:   Some different data here       Hospital          This I can find with no issues    (?m)^\bEncounter\b.*\bHOSPITAL\b.*

But what regex would I use to find only the lines that have    Encounter Info:   Some different data here         but with no HOSPITAL  at the end?

So  all the lines of data that I want to find begin with     Encounter Info:  some data here    but no  HOSPITAL  at the end.    How do I stop regex from finding the lines that do have HOSPITAL   at the end of the line?   

I do really appreciate you guys that have a full understanding of regex.    

Thank  you

Link to comment
Share on other sites

FrancescoDiMuro,

           thank you for the reply    Here is an example:

Encounter Info:  NL some different data HOSPITAL          < Do not want to find
Encounter Info:  NL still some different data HOSPITAL    < Do not want to find
Encounter Info:  NL more different data  HOSPITAL         < Do not want to find
Encounter Info:  NL different data here                   < Want to find these lines
Encounter Info:  NL HOSPITAL                              < Do not want to find
Encounter Info:  NL and different data HOSPITAL           < Do not want to find
Encounter Info:  NL HOSPITAL                              < Do not want to find
Encounter Info:  NL and more different data here          < Want to find these lines

All lines are in the same file. 

Link to comment
Share on other sites

  • Developers

Just create an small script with that data in it and the syntax you are testing which  isn't working  and post that here, as I am never feel the urge to have to retype a data and create the whole script for you. :) 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

@xcaliber13
This should fit your needs:

'(?m)^Encounter Info:.*(?<!HOSPITAL)$'

Basically, the pattern means:
(?m): Modifier. ^ and $ anchors match start and end of line;
^: start of the line;
Encounter Info: literally that string, case sensitive;
.*: every character, from 0 to unlimited;
(?<!HOSPITAL): negative lookbehind. It asserts that the line doesn't have HOSPITAL (case sensitive) at the end of the line;
$: end of the line.

:)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Hehe   :)
I asked this to you because the answer seems easy and obvious... but it is not  
... and also because I had to fight a little to find it. There are certainly other ways but I like this one  :>

#Include <Array.au3>

$txt = "Encounter Info:  NL some different data HOSPITAL    " & @crlf & _ 
    "Encounter Info:  NL still some different data HOSPITAL  " & @crlf & _ 
    "Other line:  NL more different data  " & @crlf & _ 
    "Other line:  NL more different data HOSPITAL " & @crlf & _ 
    "Encounter Info:  NL more different data  HOSPITAL  " & @crlf & _ 
    "Encounter Info:  NL different data here  " & @crlf & _ 
    "Encounter Info:  NL HOSPITAL and something more, keep this ! " & @crlf & _ 
    "Encounter Info:  NL and different data HOSPITAL    " & @crlf & _ 
    "Encounter Info:  NL HOSPITAL  " & @crlf & _ 
    "Encounter Info:  NL and more different data here  "

;$res = StringRegExp($txt, '(?m)^Encounter Info:.*(?<!HOSPITAL)\s*$', 3)

; case 1, fire lines ending with HOSPITAL + anything else
;$res = StringRegExp($txt, '(?m)^Encounter Info:(?|.*HOSPITAL(*SKIP)(*F)|.*)$', 3)

; case 2, fire lines ending with HOSPITAL + "0 or more white spaces" only
$res = StringRegExp($txt, '(?m)^Encounter Info:(?|.*HOSPITAL\h*$(*SKIP)(*F)|.*$)', 3)

 _ArrayDisplay($res)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...