I am trying to extract the 9 digit number that appears between the lookbehind values (Form & FMLA). This is the logic I am using to target my lookbehinds: (?<=Form)([\S\s]*)(?<=FMLA). Can I add another part to extract the 9 digit number? Any help would be greatly appreciated. Thanks!
Form ( For Medical Leaves of Absence ) DO NOT return this document with your original request for a leave of absence . Please email or fax this document to the HR Service Center 5 - 7 days before the date you're expected to return to work .
SECTION I : To be completed by Associate Associate's Name : Associate's Job Title : Associate ID ; Location / Store # James Doe Garden Associate 123456789 SECTION II : To be completed by a health care provider treating the associate / patient : Your patient is currently on leave of absence . Answer , fully and completely , all applicable parts . Several questions seek a response as to the frequency or duration of a condition , treatment , etc. Your answer should be your best estimate based upon your medical knowledge 1 , experience , and examination of the patient . Be as specific as you can ; terms such as "" lifetime , "" or "" indeterminate "" may not be sufficient to determine FMLA coverage .
CodePudding user response:
You can use
(?s)(?<=Form.*?)\d{9}(?=.*?FMLA)
If you need to make sure there are no other digits enclosing the nine-digit substring, use
(?s)(?<=Form.*?)(?<!\d)\d{9}(?!\d)(?=.*?FMLA)
See the .NET regex demo. Details:
(?s)
- aRegexOptions.Singleline
inline modifier flag that makes.
match across line boundaries(?<=Form.*?)
- a positive lookbehind that requiresFrom
and then any zero or more chars, as few as possible, immediately to the left of the current location\d{9}
- nine digits(?=.*?FMLA)
- a positive lookahead that requires any zero or more chars, as few as possible, and thenFMLA
substring.
CodePudding user response:
You can add this construction to your regex to match 9 consecutive digits:
([0-9]{9})
0-9
mean any digit between 0 and 9
9
in curly brackets mean repeat the previous 9 times
The final regex expression should be:
(?<=Form)([\S\s]*)([0-9]{9})(?<=FMLA)