โ06-14-2022 07:49 AM
Hi,
A simple one for the people that are expert in regex. Iโm still learning it.
So, I have a key: notes that contains a value : โ#IF:SLG-01-SL + some text hereโ
My goal is to always get the 9 characters after an โ#IF:โ
My expression I tried in the regex and works: ([#IF:])(.{0,12})
But how do I put it into a mapper?
First i check whether the notes contains โ#IF:โ if thats true it goes to the path where i need to do the regex in the mapper
$notes.replace($notes, /([#IF:])(.{0,12})/g)
but now it gives the string of the regex.
Regards
Jens
Solved! Go to Solution.
โ06-15-2022 04:35 AM
Itโs the newline character in the string that is causing the issue. The dot notation for character matching in regex does not match newlines. After a bit of thought, we can also simplify the result by using the regex group capture syntax. Try this:
$notes.replaceAll('\n','').replace(/.*#IF:(.{9}).*/g, '$1')
โ06-14-2022 11:31 AM
$notes.replace(/.*(#IF:.{9}).*/, (...args) => args[1])
It replaces the matched string with the first capture group (#IF: and the following 9 characters).
This will not work correctly when the input contains multiple matches. If thatโs the case, please let me know. You might need to use .match()
instead.
โ06-14-2022 11:50 AM
I donโt think you need to use .match() - but a slight update to @siwadonโs solution might resolve multiples within the notes:
$notes.replace(/.*(#IF:.{9}).*/g, (...args) => args[1].slice(-9))
The โgโ at the end of the pattern tells it to search the string globally. The slice(-9) will give only the 9 characters following the #IF. Multiple matches are separated with a \n (newline) character.
โ06-14-2022 10:39 PM
Hi,
I tested both but it still shows text after the nine characters. on the second one. Is it because thats a new line of text?
โ06-15-2022 04:35 AM
Itโs the newline character in the string that is causing the issue. The dot notation for character matching in regex does not match newlines. After a bit of thought, we can also simplify the result by using the regex group capture syntax. Try this:
$notes.replaceAll('\n','').replace(/.*#IF:(.{9}).*/g, '$1')