|
I tried ^[a-zA-Z\-]+$ using a string like:
10fred$erick jones
The search results didn't catch any of the disallowed characters. Am I not understanding how this pattern should work? It should have matched 10 $ and the space between the names. I'm using a utility called Expresso to pretest for results.
|
|
|
|
|
The expression ^[a-zA-Z\-]+$ will only match the string if it doesn't contain any disallowed characters.
Since the string 10fred$erick jones contains disallowed characters, it will not match that pattern.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
So in this case, if count = 0, then I should warn the user, correct? Is this considered best practice in doing it from this approach? I did try using a proper and expect input and it matches every character so I see what you're talking about.
|
|
|
|
|
Yes, if the string doesn't match that expression, then it's not valid.
The HTML5 pattern attribute[^] works in the same way - if the entered string doesn't match the pattern, then it's not valid.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
How to convert "Jan DD" to "DD/01" where D is any digit from 0 to 9 (e.g.: Jan 15>15/01)
|
|
|
|
|
Which programming language are you using?
The regex engines might differ.
|
|
|
|
|
Select Case Month
When 1 Then 'Jan'
When 2 Then 'Feb'
When 3 Then 'Mar'
When 4 Then 'Apr'
When 5 Then 'May'
When 6 Then 'Jun'
When 7 Then 'Jul'
When 8 Then 'Aug'
When 9 Then 'Sep'
When 10 Then 'Oct'
When 11 Then 'Nov'
When 12 Then 'Dec'
End + '/' + CAST(Day as varchar(2))
From TableName
|
|
|
|
|
So you want to do this in SQL?
|
|
|
|
|
Hi
I would like to extract below data from a file from Stack to "}" , Is the pattern suppose to be like "^Stack #1: ( . ) $}"
Eg Line :
Ques xx dd
Stack #1:
Task id #330
TaskRecord{ccsssew fs sfsdf sdfsdf}
Please Help!!
|
|
|
|
|
It isn't clear what the form of your input to the Regex is.
What you show as "Line" is actually 4 lines (ignoring the blank lines).
So is all of this really in a single string?
I.e.
string Line = "Ques xx dd\nStack #1:\nTask id #330\nTaskRecord{ccsssew fs sfsdf sdfsdf}";
Or are the lines separate strings in an array or list, or are they being read in line-at-a-time?
In any case, the Regex you have is not correct.
The } needs to be before the end of the line!
For the ^ and $ to match beginning and end of line (not beginning and end of the whole string) you need to use Multiline mode.
But to have . also match the \n (end of line) you need to use Singleline mode.
I suppose having both modes set can work (I haven't tried it), but it will sure look strange in the code!!!
So, if your input is separate strings that you are "processing" sequentially, you should do something like:
bool collecting = false;
List<string> collected = new List<string>();
foreach (string line in source-of-text-line-by-line)
{
if (!collecting && line.StartsWith("Stack"))
{
collecting = true;
collected.Clear();
}
if (collecting)
{
collected.Add(line);
if (line.EndsWith("}"))
{
collecting = false;
}
}
}
|
|
|
|
|
Me again. RegEx again.
Problem: I need to parse a string which consists out of Key-Value pairs.
Keys are separated from values by a "=". Values can contain a "=", but they must be escaped as "\=".
Example
Key1=Text And escaped\= More stuff\=is here Key2=Value number2
Of course the second key can contain an escaped \=, too. Long story short: Values can be a normal string (any character), except that the equal sign must be escaped.
So far I got (?<=\s|^)([\w ]+)=(\w \\=*)?(?=[ \w=]|[$]) , but it only keeps ordinary Key=value pairs, cutting of at whitespaces.
Edit: Thanks to Richard, who provided a perfectly suitable solution.
I will never again mention that Dalek Dave was the poster of the One Millionth Lounge Post, nor that it was complete drivel.
modified 20-Mar-14 13:03pm.
|
|
|
|
|
This one even fails to separate asd=w2342 asd=12333. I appreciate your effort, but not what I was looking for.
Expected:
asd
w2342
asd
12333
I will never again mention that Dalek Dave was the poster of the One Millionth Lounge Post, nor that it was complete drivel.
|
|
|
|
|
Hello,
I use VB.net for this one...
(BTW) i know this isn't the thing you're looking for, but i hope i could at least help you...
Public Function ListItems As List(Of Item)<br />
Dim Result As New List(Of Item)<br />
<br />
Dim items As String = "asd=w2342 asd=12333"<br />
Dim parts() As String = Split(items, " ") 'First off i'm gonna split the items devided by spaces<br />
<br />
For Each part As String In parts<br />
<br />
Dim items() As String = Split(part, "=") 'Second i'm going to split the part into two seperate values<br />
Dim Value1 As String<br />
Dim Value2 As String<br />
<br />
Value1 = items(0)<br />
Value2 = items(1)<br />
<br />
Result.Add(New Item(Value1, Value2) 'Then you can assign these value to a class or something else you want to use this data in...<br />
<br />
Next<br />
<br />
Return Result<br />
<br />
End Sub
I hope i could help you a bit in finding an answer to your problem...
With kind regards,
Niels Koomans
|
|
|
|
|
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.
|
|
|
|