|
Marco Bertschi wrote: second key can contain an escaped \= Are you sure - isn't it 'second value'?
What the separator between one key-value pair to the other?
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Kornfeld Eliyahu Peter wrote: Are you sure - isn't it 'second value'?
Nicely catched my brainfart
Kornfeld Eliyahu Peter wrote:
What the separator between one key-value pair to the other?
A space. I know, that doesn't really makes it easier
I will never again mention that Dalek Dave was the poster of the One Millionth Lounge Post, nor that it was complete drivel.
|
|
|
|
|
But space also can be in the value part, but not in the key part - Am I right?
In that case I'm not sure you have a pure regex solution...
(I would like to have the time to dig in - it's an interesting challenge, unfortunatelly I have not )
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Kornfeld Eliyahu Peter wrote: But space also can be in the value part, but not in the key part - Am I right?
Yes, and that makes the easy question a hard one.
I will never again mention that Dalek Dave was the poster of the One Millionth Lounge Post, nor that it was complete drivel.
|
|
|
|
|
As whitespace (or space only) can be also part of value and also separator for key-value pairs - I'm almost sure you wasting your time by looking for a regex solution...Consider it...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Peter,
see Richard's answer below. It works like a charm, and will most certainly help you as much as it did help me. I wasn't wasting my time, and the efficiency gain makes the invested time worth.
I will never again mention that Dalek Dave was the poster of the One Millionth Lounge Post, nor that it was complete drivel.
|
|
|
|
|
I see...I hope you aware that it's a .NET only extension and it will not work anywhere else...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Kornfeld Eliyahu Peter wrote: .NET only extension
May I ask what about it is .Net only?
I will never again mention that Dalek Dave was the poster of the One Millionth Lounge Post, nor that it was complete drivel.
|
|
|
|
|
The group definition ?<group> is .NET only. It brings a kind of recursive search into regex (that lacks it)...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Well... damn.
I got this one going here
^((\\b[^\\s=]+)=(([^=]|\\\\=)+))*$
which gives me the last key-value pair of the string. I can then chop off the extracted string and run the regex again. Dirty, but does the job.
I will never again mention that Dalek Dave was the poster of the One Millionth Lounge Post, nor that it was complete drivel.
|
|
|
|
|
Yeah...That what I though - no pure regex for you know. Not without extensions...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Bummer.
But that one got me, evntually gonna write a short article about it...
I will never again mention that Dalek Dave was the poster of the One Millionth Lounge Post, nor that it was complete drivel.
|
|
|
|
|
Beware - it's the second article you promise me! I didn't see the first jet...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
What was the first one again?
I will never again mention that Dalek Dave was the poster of the One Millionth Lounge Post, nor that it was complete drivel.
|
|
|
|
|
Syslog protocol...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
I started the implementation, but I'm a bit busy with my final projects for my apprenticeship.
What I've done so far is a good bit of the message classes, have a look, if you want to...[^]
I will never again mention that Dalek Dave was the poster of the One Millionth Lounge Post, nor that it was complete drivel.
|
|
|
|
|
Assuming that keys can't contain white-space or escaped "=" characters, this should work:
^((?<key>\b[^\s=]+)=(?<value>([^=]|\\=)+))+$
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard,
this one works like a charm, you can't believe how much you helped me
I will never again mention that Dalek Dave was the poster of the One Millionth Lounge Post, nor that it was complete drivel.
|
|
|
|
|
Oh, so the puzzle was here all the time. Well, OG found a solution to you, and I got one too witch OG helped me a little with:
(\w+(?=\=))|((?<!\\)(?<=\=)(.+?)((?=(\s\w+\=))|$))
This sould work in all cases, or so I hope 
|
|
|
|
|
Something else to consider... when I've needed to do something like that I did it right-to-left.
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
i want to separate voice and background music from an audio file, for this i have use BSS method. Can any one provide me MATLAB code for BSS(blind source separation)
|
|
|
|
|
And what does this have to do with Regular Expressions[^]?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I can't see how you can't see the connection...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Yess, I am still struggling with RegEx.
What I have done so far is to validate a string whether it consists of printable ASCII chars only.
string host;
public string Host
{
get { return host; }
set
{
Regex regex = new Regex(@"(\40-\176)");
Match match = regex.Match(value);
if (match.Groups.Count == 1)
{
host = match.Groups[1].Value;
}
}
}
Is there a shorter way of approaching this?
Also, the RegEx currently produces no match if there is an invalid ASCII char in the string, what would I need to do to just remove the faulty part?
Clean-up crew needed, grammar spill... - Nagy Vilmos
|
|
|
|
|
I'm not convinced by your Regex - you're matching the literal string " -~" and capturing it to a group. To indicate a range of characters, you need some square brackets:
([\x20-\x7e])
(I prefer to use hex values, since it's more obvious that they're not decimal values; you don't have to remember that the default is octal.)
Since you just want to remove any characters that aren't in the specified range, the simplest approach is to negate the range and use the Replace method:
set
{
host = Regex.Replace(value, @"[^\x20-\x7e]", string.Empty);
}
However, for a simple case like this, Regex is probably overkill; you could simply loop through the characters, discarding any that you don't want:
set
{
if (!string.IsNullOrEmpty(value))
{
char[] validChars = new char[value.Length];
int validCharIndex = 0;
foreach (char c in value)
{
if ('\x20' <= c && c <= '\x7e')
{
validChars[validCharIndex] = c;
validCharIndex++;
}
}
if (validCharIndex == 0)
{
value = string.Empty;
}
else if (validCharIndex != value.Length)
{
value = new string(validChars, 0, validCharIndex);
}
}
host = value;
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|