Hi friend
I want to extract the value between Base: and Val:.
I think the Regex could be the best solution.
String:
Correcao: 10/10/23 Usr: FSIGNORE Base: 6.078,13 Val.: 758,70
Result Goal: 6.078,13
How can I achieve this result?
Hi friend
I want to extract the value between Base: and Val:.
I think the Regex could be the best solution.
String:
Correcao: 10/10/23 Usr: FSIGNORE Base: 6.078,13 Val.: 758,70
Result Goal: 6.078,13
How can I achieve this result?
You can use a String Manipulation node with
substr($column1$,indexOf($column1$,"Base:" )+6 ,indexOf($column1$,"Val.:" )-indexOf($column1$,"Base:" )-6)
gr. Hans
Hi @Felipereis50 … choices! Yes, you can also do it using regex. You have a variety of nodes that can do it, but the regex for each may be slightly different:
Extract value between strings using regex.knwf (13.2 KB)
String Manipulation
regexReplace($column1$,".*Base:\\s*(.*)\\s*Val\\.:.*","$1")
String Replacer
.*Base:\s*(.*)\s*Val\.:.*
(replace with $1
)
Regex Split
.*Base:\s*(.*)\s*Val\.:.*
In each case the (.*)
“captures” the part you want, but you will see you have to escape certain characters such as the “.” after Val, and in the case of String Manipulation you have to “escape” the “escape” by using \\
Owww
I see
Great.
I think this will cover the dynamic possibility to the hole string vary.
But between the two words will not vary the number of the characters.
Thanks my friend
You’re an expert of regex?
I will not lie, I have tried to use chatGpt to write the formula for me, but no success.
This expressions like “$1” doesn’t explain in the “regexReplace”.
So is more difficult to learn alone.
I will try all of your suggestions to learn alone (just a little bit). I think regex amazing but very difficult to learn.
Yes the $1
notation can seem confusing at first, but it’s relatively straightforward
Basically if you have a regex string such as Dog: Rover Cat: Felix
and you want to “capture” the names of the Dog and Cat, you could write a regex something like this:
Dog:\s*(.*)\s*Cat:\s*(.*)
the \s*
simply says “any amount of white space” which we can ignore.
Putting parentheses around part of the regex means “capture this part”. The (.*)
parts “capture” the text that we are interested in. These are known as “capture groups”. Each capture group can be represented in the “replacement” section of String Manipulation, or String Replacer, by using $
followed by the number of the group. They are numbered 1,2… from left to right. So what is captured by the first (.*)
can be referenced as $1 and what is captured by the second (.*)
can be referenced by $2.
We could then replace our text with this:
The dog is called $1 and the cat is called $2
As $1 and $2 are effectively place-holders for the two capture groups. This would result in the following output:
The dog is called Rover and the cat is called Felix
Note that $ without the number means “end of line” in regex, and whether we are talking about a capture group or “end of line” is really down to the context in which it is used, and the presence of the numbers.
(oh and I’m no regex expert. I know enough to generally do the stuff I need to do. There are other regulars on the forum who are far more adept than me at this, and then I too go to chatgpt and of course sites like regex101.com and rexegg.com )
Owwww
Amazing explanation.
Very good for other friends here in the forum.
Thank you very much for your time and explanation.
I will try to learn more about regex, because a problem always appears, and can be solved by regex in the safest way.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.