# Extracting percentage value from string via regex seems not to work

**URL:** <https://forum.knime.com/t/extracting-percentage-value-from-string-via-regex-seems-not-to-work/42522>\
**Category:** KNIME Analytics Platform\
**Tags:** regex\
**Created:** [May 5, 2022, 9:16am UTC](https://forum.knime.com/t/extracting-percentage-value-from-string-via-regex-seems-not-to-work/42522 "2022-05-05T09:16:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Residentstiefel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/r/0ea827/32.png) [@Residentstiefel](https://forum.knime.com/u/Residentstiefel)\
**Post date:** [May 5, 2022, 9:16am UTC](https://forum.knime.com/t/extracting-percentage-value-from-string-via-regex-seems-not-to-work/42522/1 "2022-05-05T09:16:31Z")

</div>

Hi community,

I want to extract a percentage value from a string like:  
“1234, Name of Entity, 29.5%, Germany”

My extract should contain the 29.5%.  
The regex 101 code works, however, I cannot make the string manipulation regex matcher work. I only receive a false as output. Any clues?

My REGEX: \d+(.\d+)?%  
Example how it works: [regex101: build, test, and debug regex](https://regex101.com/r/rIaojZ/1)

My String manipulation configuration:  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/4/b/4bc96f05db475feb3fab9d301e5712bdcda6b3e6.png)

Best regards,  
Stiefel

---

<div class="post-metadata">

**Author:** ![SamirAbida](https://forum-cdn.knime.com/user_avatar/forum.knime.com/samirabida/32/28904_2.png) [@SamirAbida](https://forum.knime.com/u/SamirAbida)\
**Post date:** [May 5, 2022, 12:33pm UTC](https://forum.knime.com/t/extracting-percentage-value-from-string-via-regex-seems-not-to-work/42522/2 "2022-05-05T12:33:00Z")

</div>

Hi @Residentstiefel,

You can use [Column Expressions – KNIME Hub](https://hub.knime.com/knime/extensions/org.knime.features.expressions/latest/org.knime.expressions.base.node.formulas.FormulasNodeFactory) this way :

` column("column1").match(/[0-9]+.[0-9]?%/)[0]`  
or  
` column("column1").match(/\d+.\d?%/)[0]`

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/6/6/66e5daa02908d2a98debe118be30418c7cb195a0.png)

Get explanation of this regex by going on [regex101: build, test, and debug regex](https://regex101.com/)

If you use [String Manipulation – KNIME Hub](https://hub.knime.com/knime/extensions/org.knime.features.javasnippet/latest/org.knime.base.node.preproc.stringmanipulation.StringManipulationNodeFactory), is it a normal behavior for regexMatcher to return “True or False”, but you could use regexReplace. But you’ll have to inverse your regex to match the non-wanted string and replace it with nothing, I guess.

Regards, Samir

---

<div class="post-metadata">

**Author:** ![elsamuel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/e/b4bc9f/32.png) [@elsamuel](https://forum.knime.com/u/elsamuel)\
**Post date:** [May 5, 2022, 1:37pm UTC](https://forum.knime.com/t/extracting-percentage-value-from-string-via-regex-seems-not-to-work/42522/3 "2022-05-05T13:37:46Z")

</div>

I’d use the Regex Extractor node for this.

---

<div class="post-metadata">

**Author:** ![victor\_palacios](https://forum-cdn.knime.com/user_avatar/forum.knime.com/victor_palacios/32/37922_2.png) [@victor\_palacios](https://forum.knime.com/u/victor_palacios)\
**Post date:** [May 5, 2022, 2:24pm UTC](https://forum.knime.com/t/extracting-percentage-value-from-string-via-regex-seems-not-to-work/42522/4 "2022-05-05T14:24:33Z")

</div>

I would use the Cell Splitter node by comma splitting instead. Very simple.

Here are [various examples of regex](https://hub.knime.com/victor_palacios/spaces/Public/latest/Various%20Examples%20of%20Regex%20in%20KNIME~J1anMyaS7MMiRV29) in KNIME.

Extraction is done a little differently in KNIME. As well the \d may require several “\” That is why I usually use [0-9] instead. If you really want to use Regex, I would recommend the String Manipulation node: regexReplace($column1$, “.+\\s([0-9]+.[0-9]+%).+”, “$1”)

---

<div class="post-metadata">

**Author:** ![qqilihq](https://forum-cdn.knime.com/user_avatar/forum.knime.com/qqilihq/32/50_2.png) [@qqilihq](https://forum.knime.com/u/qqilihq)\
**Post date:** [May 5, 2022, 3:02pm UTC](https://forum.knime.com/t/extracting-percentage-value-from-string-via-regex-seems-not-to-work/42522/5 "2022-05-05T15:02:53Z")

</div>

As mentioned by @elsamuel, with the [Regex Extractor](https://nodepit.com/node/ws.palladian.nodes.extraction.regex.RegexExtractorNodeFactory) you get a live extraction preview similar to common different regex tools, but directly in your workflow for your data:

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/9/4/94fa2c4e24ebd4f31b7745a3d02fa5e9f1c0287a.jpeg)

You can even define several groups at once (optionally including names) and map them to separate output columns.

I used the following regex here `\d+(?:\.\d+)?%` which considers the decimal part optional and would also match e.g. “29%”.

The Regex Extractor is available as free extension within the Palladian extensions which are exclusively distributed through NodePit and available here:

> **[Palladian](https://nodepit.com/product/palladian)**
>
> Your survival toolkit in the daily jungle of Web Information Extraction, Text Classification, and Geo Data.

For any questions, feedback, etc. about the node in particular, or Palladian in general, don’t hesitate to reach out on the forums!

–Philipp

---

<div class="post-metadata">

**Author:** ![Daniel\_Weikert](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/d/e47c2d/32.png) [@Daniel\_Weikert](https://forum.knime.com/u/Daniel_Weikert)\
**Post date:** [May 5, 2022, 5:21pm UTC](https://forum.knime.com/t/extracting-percentage-value-from-string-via-regex-seems-not-to-work/42522/6 "2022-05-05T17:21:03Z")

</div>

> [@Residentstiefel](#):
>
> 1234, Name of Entity, 29.5%, Germany

._(\b\d+?.?\d+?%)._

---

<div class="post-metadata">

**Author:** ![Residentstiefel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/r/0ea827/32.png) [@Residentstiefel](https://forum.knime.com/u/Residentstiefel)\
**Post date:** [May 7, 2022, 12:03pm UTC](https://forum.knime.com/t/extracting-percentage-value-from-string-via-regex-seems-not-to-work/42522/7 "2022-05-07T12:03:04Z")

</div>

Hi community,

Thanks for all the replies. I ended up utilizing the Regex Extractor, which is amazing. Column expressions also worked! However, what puzzles me, is that using the same Regex did not work in the string manipulation, which was my starting point. Pretty frustrating to see it work in the Regex101 and not in dedicated generic KNIME nodes… Actually, I gave up trying to make the string manipulation work (taking into account the extra backslashes etc.) 😕 Yet, there are so many other nodes that help out in these situations 😉

Thanks and cheers,  
Stiefel

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [May 14, 2022, 5:45pm UTC](https://forum.knime.com/t/extracting-percentage-value-from-string-via-regex-seems-not-to-work/42522/9 "2022-05-14T17:45:24Z")

</div>

Closed on May 14, 2022, 5:45pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
