问题
I understand that .NET's regex works with strings, but I need an implementation for byte[] arrays. Are there any open source implementation in .NET? Does byte[] regex exists for any other programming language other than C# which I can use to build a wrapper for it in C#?
My limitation is that I have to stay within byte arrays. So cannot do any conversions to strings.
Thanks for the advice.
回答1:
Regular expressions work with strings. A byte array can contain just about any data. So if you want to use regular expressions convert this byte array into a string using the encoding that was used to encode it. For example if your byte array represents a UTF-8 encoded string:
byte[] buffer = ...
string foo = Encoding.UTF8.GetString(buffer);
// Go ahead and use regexes on foo
来源:https://stackoverflow.com/questions/8907911/are-there-any-well-know-regex-libraries-for-net-specifically-for-byte-arrays