I wish to separate the following data using regex function as follows:
Function to be used:
let fx=(text,regex)=>
Web.Page(
"<script>
var x='"&text&"';
var y=new RegExp('"®ex&"','g');
var b=x.match(y);
document.write(b);
</script>")[Data]{0}[Children]{0}[Children]{1}[Text]{0}
in
fx
Agurments:
- text - Column1
- List item
regex - \\d+\\.?\\d+
This successfully extracts the numerical values, however:
- I am unsure if this is the correct regex to remove the first integer/number.
- I am unsure how to use regex to extract only the units. It seems to run into errors despite various attempts. e.g. \D+ doesn't return the non-numerical values despite it working on the link. This being said for 15 ng/m3 if this did work it would only return ng/m3. I wonder if there is an issue with the function itself.
M Code:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
#"Invoked Custom Function1" = Table.AddColumn(#"Changed Type", "fnRegexExtr2", each fnRegexExtr2([Column1], "\\d+\\.?\\d+")),
#"Invoked Custom Function" = Table.AddColumn(#"Invoked Custom Function1", "fnRegexExtr2.1", each fnRegexExtr2([fnRegexExtr2], "\\D+"))
in
#"Invoked Custom Function"
update with "^[^\s]+":
data:
1200 mg/kg bw/day
24 mg/kg/day
0.79 mg/kg bw/day
15 ng/m3
15 ng/m 3
Not Limited
30mg/m³