Regex Parsing
suggest changeSyntax
new Regex(pattern);
//Creates a new instance with a defined pattern.Regex.Match(input);
//Starts the lookup and returns the Match.Regex.Matches(input);
//Starts the lookup and returns a MatchCollection
Parameters
| Name | Details|
| ------ | ------ |
| Pattern | The `string` pattern that has to be used for the lookup. For more information: [msdn][1]|
| RegexOptions *[Optional]* | The common options in here are `Singleline` and `Multiline`. They are changing the behaviour of pattern-elements like the dot (.) which won't cover a `NewLine` (\n) in `Multiline-Mode` but in `SingleLine-Mode`. Default behaviour: [msdn][2] |
| Timeout *[Optional]* | Where patterns are getting more complex the lookup can consume more time. This is the passed timeout for the lookup just as known from network-programming.|
2: https://msdn.microsoft.com/en-US/library/yd1hzczs(v=vs.110).aspx#Default
Remarks
Needed using
using System.Text.RegularExpressions;
Nice to have
- You can test your patterns online without the need of compiling your solution to get results here: Click me
- Regex101 Example: Click me
Especially beginners are tended to overkill their tasks with regex because it feels powerful and in the right place for complexer text-based lookups. This is the point where people try to parse xml-documents with regex without even asking theirselfes if there could be an already finished class for this task like XmlDocument
.
Regex should be the last weapon to pick agains complexity. At least dont forget putting in some effort to search for the right way
before writing down 20 lines of patterns.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents