I have this text and want to extract the text after "Sample Type: " and before the \r character at the end of that line.
HPV PRIMARY SCREENING
Specimen Type: Liquid based cytology (SurePath)
HrHPV: Not detected
CYTOLOGY
Site: Cervical
The specimen is satisfactory for evaluation.
NEGATIVE FOR INTRAEPITHELIAL LESION OR MALIGNANCY.
The next HPV screening test should be taken in 5 years, based on the
NCSP Register history. Overseas tests are noted on the request form
but are not recorded in the NCSP Register. This recommendation is
based on current test results and the NCSP Register records only and
may need to be modified if other results were reported overseas.
Please forward copies of overseas pathology reports or an overseas
specialist letter confirming dates and results of previous pathology
tests to the NCSP Register.
I have tried this regex in the Find Matching Patterns activity [(?<=Specimen Type: \s+)[\S\s]?(?=\r)] but this matches every line in the string apart from the last line.
Use it in an assign activity like this:
Left assign
str_Result
Right assign
system.Text.RegularExpressions.Regex.Match(yourStr, “(?<=Specimen Type:).+”).ToString.Trim
Some feedback on your provided pattern. A good attempt with the right approach but with a few mistakes:
There was an extra space after the colon ‘:’ (meaning nothing was going to match unless there was a 2+ spaces).
The square brackets matching all whitespace and non whitespace characters would match everything
The quantifier on the square brackets ? was incorrect as it mean ‘0 or 1’ character. You should have used a ‘+’ as it meant you are expecting 1 to infinite.
Another way of writing your intended pattern with less characters is like this.
You can check out my Regex megapost if you want to see few more examples.
I had an issue with the " characters in
system.Text.RegularExpressions.Regex.Match(yourStr, “(?<=Specimen Type:).+”).ToString.Trim
where UiPath required me to delete them and re-enter them - somehow it does not recognise the ones copied from the forum message and reports this error:
“Assign: Expression Activity type ‘VisualBasicValue`1’ requires compilation in order to run. Please ensure that the workflow has been compiled.”