Regex pattern for sample text

Sample Text :

[System|* Profile : * Abc Def\n *Function : * AAA]

Expected Output :
Profile value stored in variable : Abc Def

Function value stored in variable : AAA

Pattern : Values of Profile , Function are dynamic.
\n will always come in profile value parameter.

  • will appear or may be not.

I’ve tried with below regex pattern but looking for optimised solution:

List = {“Profile”,“Function”}.Select(Function(x) Regex.match(Sample text.string,“(?<=”& x &" :).*).ToString).toList and store to list.

But issue appears with Profile value : * Abc Def\n* Function : AAA]

Function value appears as * AAA] then i tried with replace function to extract AAA only.

Hi @Sonalk

You are in the right place for help :sunglasses:

There are plenty of people who can help.

I hopefully have a pattern you can use. You can view my pattern below and even insert more samples. This pattern is reliant on three things. Even these are missing the pattern will be unreliable.

  • colons “:”
  • square brackets “]”
  • a backslash "" from the text “\n” found in the sample. OR an asterisk “*”

If the pattern is unreliable please let tell us more about the pattern? What is consistent etc.

Hopefully this helps you :blush:

1 Like

Hey @Sonalk!! Lets take a look!

→ To extract the “Profile Value” use the regex

(?<=Profile : )[\s\S]*(?=\\n)

Example:

→ To extract the “Function Value” use the regex

(?<=Function : )[\s\S]*(?=])

Example:

Hope this helps!

1 Like

Hi @Steven_McKeering : Pattern is having fixed structure.

Only change might happen with * characters in below string sample
[System|* Profile : * Abc Def\n *Function : * AAA]

Hi @gabrielribas4 : Thanks for sharing regex expression.

I have published * in existing sample but unfortunately it was not displayed in query. I have again updated my query.

Could you check and update your regex to mark this as solution?

Hey

Try this new Regex pattern then. Hopefully I understood your sample okay.


Hey @Sonalk! We can just add “*” char in ourRegex. Take a look!

→ To extract the “Profile Value” use the regex

(?<=Profile : \* )[\s\S]*(?=\\n)

→ To extract the “Function Value” use the regex

(?<=Function : \* )[\s\S]*(?=])

Hope this helps!

Thanks @Steven_McKeering @gabrielribas4 for sharing regex expression.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.