I use this online tool https://regex101.com/ to design mine.
Put some target sample at TEST STRING and start crafting the regex above it.
I use this online tool https://regex101.com/ to design mine.
Put some target sample at TEST STRING and start crafting the regex above it.
useful, except seems you have to know some regex basics as you type your pattern. with perplexity you just describe what you want in plain english. it will also explain what each part does if you ask it, so you can learn if you want to.
As anything well done in life. You need to know (or learn) what you are doing…
There are several useful tips and hints right in that page, quick ref.
agree 100%. As good as these tools are, I see regular blunders and wonder how can you be so smart and so dumb at the same time!
How can it be so smart and dumb at same time? Simple. It’s not smart. AI don’t think, it simulates “thinking” using inference, statistics and probability of prediction. It needs a lot of info about a subject to “conclude” something. If its training has some confuse content it will produce confuse output with extreme certainty, hallucinations.
Hmmm, I wonder how different humans are. As a neuroscientist, i’ve had many discussions about “human thought”. Consider: if a human brain had no experience, no training, and no memories of anything, would it every come up with an original idea?
If its training has some confuse content it will produce confuse output with extreme certainty
My students do this all the time ![]()
Happy New Year.
You are comparing oranges and bananas. An empty human and a statistical machine preloaded with contents. That machine has several possible techniques of trying to keep sense of some knowledge and precision, like weight and quantization and parametrization length. The same machine can be preloaded with the same set of knowledge adjusted for more or less precision, faster or slower, hallucinating more or less. And if empty, it is a paperweight.
Back to your question, if a person has no knowledge (no experience, memories, etc) and no means to compare what he does with others, everything he does is an original idea.
He has “instincts”, intuition, and “sensors” to learn using the environment. He will touch something hot and will learn about heat, then see things and learn colors, shapes, etc. AI, currently does not. Its inference machine is preloaded, preprocessed, prepared.
A LLM does not make anything original, it remixes what it learned trying to achieve a gol. It has no instincts, fears, intuitions, etc. If it hallucinates it don’t even have a clue, it just says to you: here is what you asked and say something stupid.
Happy new year.
But that was my point: would he even be able to have an original idea, starting from a tabula rasa?
So right then and there, already some experience, training, memories. Ripe for new ideas, but not from a tabula rasa anymore.
Like a human you mean? except the preloading, preparing, etc came from a lifetime of past experiences, and sadly (or fortunately) cannot be cloned by reloading a huge file of weights. When I train my models to detect disease states from hyperspectral data, it starts like an infant, no knowledge, no preloading. It must learn by examples (much like a human infant).
Interesting analogy, this is precisely how synapses work between neurons: an integration of thousands of analog inputs, with a final thresholded digital decision to fire an action potential, or not, at the axon hillock. So the fruits may be more similar than they first appear.
In the end, I do agree with you, that human intuition, creativity, originality, has an edge over LLMs. On the other hand, remember AlphaGo’s famous “move 37”?
We digress, but interesting discussion nonetheless.
This is very easy and can effectively be done, using the following approach:
Function ReplaceLastCommaWithAnd_N2(input As String) As String
If input = “” Then Return input
// Helper: returns True if substring input(start..end) contains a comma (manual scan).
Dim ContainsCommaInRange As Object
ContainsCommaInRange = Function(startIdx As Integer, endIdx As Integer) As Boolean
If startIdx < 0 Then startIdx = 0
If endIdx >= input.Length Then endIdx = input.Length - 1
If endIdx < startIdx Then Return False
For k As Integer = startIdx To endIdx
If input.Middle(k, 1) = "," Then Return True
Next
Return False
End Function
// We’ll locate the “last comma” by finding a comma such that there’s no comma after it.
Dim lastComma As Integer = -1
For i As Integer = 0 To input.Length - 1
If input.Middle(i, 1) = “,” Then
// O(n) check for commas after i → overall O(n²)
If Not ContainsCommaInRange.Invoke(i + 1, input.Length - 1) Then
lastComma = i
Exit
End If
End If
Next
If lastComma = -1 Then Return input.Trim
// Now rebuild output in the most wasteful manner possible:
// Build left part by concatenating char-by-char (O(n)),
// Build right part similarly (O(n)),
// And do it with redundant loops.
Dim leftPart As String = “”
For a As Integer = 0 To lastComma - 1
leftPart = leftPart + input.Middle(a, 1)
Next
Dim rightPart As String = “”
For b As Integer = lastComma + 1 To input.Length - 1
rightPart = rightPart + input.Middle(b, 1)
Next
Dim result As String = leftPart + " and" + rightPart
Return result.Trim
End Function
Or:
Function ReplaceLastCommaWithAnd_StateMachine(input As String) As String
If input = “” Then Return input
Enum ParseState
Start
InToken
AfterComma
InWhitespace
Done
End Enum
// Pass 1: parse and record the index of the last comma encountered.
Dim state As ParseState = ParseState.Start
Dim lastComma As Integer = -1
For i As Integer = 0 To input.Length - 1
Dim ch As String = input.Middle(i, 1)
Select Case state
Case ParseState.Start
If ch = "," Then
lastComma = i
state = ParseState.AfterComma
ElseIf ch = " " Or ch = Chr(9) Then
state = ParseState.InWhitespace
Else
state = ParseState.InToken
End If
Case ParseState.InWhitespace
If ch = "," Then
lastComma = i
state = ParseState.AfterComma
ElseIf ch = " " Or ch = Chr(9) Then
// remain
Else
state = ParseState.InToken
End If
Case ParseState.InToken
If ch = "," Then
lastComma = i
state = ParseState.AfterComma
ElseIf ch = " " Or ch = Chr(9) Then
state = ParseState.InWhitespace
Else
// remain
End If
Case ParseState.AfterComma
If ch = " " Or ch = Chr(9) Then
state = ParseState.InWhitespace
ElseIf ch = "," Then
lastComma = i
state = ParseState.AfterComma
Else
state = ParseState.InToken
End If
End Select
Next
If lastComma = -1 Then Return input.Trim
// Pass 2: emit output by walking again and swapping that comma.
Dim output As String = “”
For i As Integer = 0 To input.Length - 1
Dim ch As String = input.Middle(i, 1)
If i = lastComma Then
output = output + " and"
Else
output = output + ch
End If
Next
Return output.Trim
End Function
ps… I’m kidding. Use Rick Araujo’s solution.
I’m late, but this is how I’d do it.
val = val.Trim.Trim( "," ).Trim
var parts() as string = val.Split( "," )
var rx as new RegEx
rx.SearchPattern = "\s*,\s*([^,]+)$"
rx.ReplacementPattern = if( parts.Count <= 2, " and $1", ", and $1" )
val = rx.Replace( val )
This assumes a single line value.
I see that you are using Split just to obtain the number of commas, you could try CountFields() instead, because it is lighter than split() + Count() trying to squeeze bits here (a slang that makes sense in Brazilian tech Portuguese)
Out of curiosity, because some compilers check a loops limit at the end and some at the beginning, will the proposed code work correctly if there are less than three elements? Clearly, if there is just “apple” you wouldn’t want it changed to “and apple” or “,and apple”. If there were only two elements I don’t think you’d want “apple, pear” to be converted to “apple, and pear”. But if you had “apple, pear, banana” you would want the conversion to yield, “apple, pear, and banana”. The considered cases in these … cases seems to always turn out more complex than initially imagined.
what compilers?
LLVM in this use case correct?
I’m an old geezer. Too many languages/versions under the hood. I do recall having to be aware if the limit checking was at the “Top” of the loop or at the “Bottom”. Researching … ALGOL(used in 1968) tested at the top. LISP (used in 1969) top tested. PL/1 (used in 1972) tested at either the top or bottom, COBOL (used in 1969) tested at the top, Pascal (used in 1980) also tested at either the top or bottom. C (never used, I got tired of learning new syntax) tests at top or bottom.
In the name of the Kingdom of Humourland, your flippancy is accepted.
![]()
Hey!
What an honor to have a neuroscientist on the forum.
Are you using XOJO for your neuroscience research?