0

I do have to parse specific Information from Report headers in Text Format
Since I do have to perform this through Regular expressions in VB Script I cannot make use of the Look Ahead features of Regex.

Typical use cases to cover for Regular expressions would be

1) User Name : Clark Kent
Extracted by Regex: "Clark Kent" for any line Starting with "User Name :"
2) User Name Clark Kent
Extracted by Regex: "Clark Kent" for any line Starting with "User Name" and delete all leading and trailing blanks from " Clark Kent "
3) User Name: Clark Kent Sample ID : 1234
Extracted by Regex: "Clark Kent" from any line starting with "Clark Kent" and Ending with "SampleID :"

Any Help for this example would be highly appreciated

3
  • I tried to find examples and studied the command reference, but almost all hints for this hint point to LOOKBEHIND , but this is not available in VB Commented Aug 18, 2014 at 14:37
  • All three of your examples start with "User Name" so I don't fully understand the third scenario. How is this different? Commented Aug 18, 2014 at 14:41
  • Scenario 1 and 2 should find anything behind the identifier "User Name" or "User Name :" Scenario 3: Find anything BETWEEN "Clark Kent" and the string(identifier) "SampleID :" Commented Aug 18, 2014 at 14:53

1 Answer 1

1

My regex skills aren't the greatest but this pattern works for your three examples. It currently only looks for and returns <first name><space><last name>, but it could be adapted to handle more complicated scenarios.

With New RegExp
    .Pattern = "^User Name\s*:?\s*(\w+\s\w+)\s*(?:Sample ID)?"
    Set Matches = .Execute(strLine)
End With

If Matches.Count > 0 Then strName = Matches(0).SubMatches(0)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.