2

I would like to combine a few expressions to get 3 different results per line.

Example: element\data\elements.data|44a0b61d1952973f52ad54cb911c0e3e|33095223

.*?element(?:(?!\|).)* retrieves element\data\elements.data

(?<=\|)(.*?)(?=\|) retrieves 44a0b61d1952973f52ad54cb911c0e3e

(?<=\|)[0-9]*\r retrieves 33095223

But for me to get these I currently am doing 3 different RegEx, and I would like to limit it down to only one to get the 3 results I need and set them to different variables.

I have looked into doing a Dictionary but those only allow 2 variables, while I need 3.

4
  • The expressions a, b and c match a, b and c respectively. How do you match abc? Commented Jan 24, 2014 at 20:46
  • @GrantWinney How exactly would I achieve that? Commented Jan 24, 2014 at 20:47
  • I'm confused on your objection to using a Dictionary. You can have Dictionary<string,Collection<type>()>, and if all of your parameters for retrieval are unique that would make a great key. Commented Jan 24, 2014 at 20:56
  • @FelixCastor could you give a quick example? Commented Jan 24, 2014 at 20:59

2 Answers 2

7

You could just split on the vertical pipe:

var elements = string.Split('|');

The resulting string array would contain:

  • element\data\elements.data
  • 44a0b61d1952973f52ad54cb911c0e3e
  • 33095223
Sign up to request clarification or add additional context in comments.

1 Comment

+1 This worked perfectly, is there a way to set each string array to a variable? like var file = "element\data\elements.data", var hash = 44a0b61d1952973f52ad54cb911c0e3e, and var bytes = 33095223
0

For having a Regex with multiple matches you should take a look add | between your expressions. This will then return you all the results matching any of the pattern, with no distinction which string was found by which match.

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.