# regex extractor node

**URL:** <https://forum.knime.com/t/regex-extractor-node/81290>\
**Category:** KNIME Analytics Platform\
**Tags:** regex\
**Created:** [July 23, 2024, 11:17pm UTC](https://forum.knime.com/t/regex-extractor-node/81290 "2024-07-23T23:17:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![NabilEnn](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/n/59ef9b/32.png) [@NabilEnn](https://forum.knime.com/u/NabilEnn)\
**Post date:** [July 23, 2024, 11:17pm UTC](https://forum.knime.com/t/regex-extractor-node/81290/1 "2024-07-23T23:17:17Z")

</div>

Hello all, i was wondering if anyone has any input on how i would extract text under a keyword using regex extractor or any other nodes that are able to do so. for example if i have the keyword “Name:” and one line under it has the actual name i want to extract how do i get that. In a scenario where there is no other keywords to use that are on the same line as the actual name.

---

<div class="post-metadata">

**Author:** ![rfeigel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rfeigel](https://forum.knime.com/u/rfeigel)\
**Post date:** [July 24, 2024, 3:06am UTC](https://forum.knime.com/t/regex-extractor-node/81290/2 "2024-07-24T03:06:04Z")

</div>

Is what you’re calling “keyword’” actually a column header? Also, do you only want to extract the first data element (name) after the column header or everything in the column? If you post a small data set and explain exactly what you want it would help.

---

<div class="post-metadata">

**Author:** ![NabilEnn](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/n/59ef9b/32.png) [@NabilEnn](https://forum.knime.com/u/NabilEnn)\
**Post date:** [July 24, 2024, 4:02pm UTC](https://forum.knime.com/t/regex-extractor-node/81290/3 "2024-07-24T16:02:08Z")

</div>

No so basically if i have a medical bill or invoice, and i only want the name and no other text i usually use a regex expression to extract the text after the word “Name:” because the text is on the same line as the keywoord. Which is the keyword im using for the regex expression in regex extractor. For example if i have a medical bill, and the name i want to extract is printed like this “Name: John Doe” i want John Doe and nothing else out of the page. i use a regex expression to extract text after the word “Name” i have no problems with that but now i have an issue where it is printed like this  
“Name:  
John Doe”  
so the actual name of the person is under the keyword “Name”. How could i use the keyword “Name:” and extract under it to get “John Doe”

---

<div class="post-metadata">

**Author:** ![NabilEnn](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/n/59ef9b/32.png) [@NabilEnn](https://forum.knime.com/u/NabilEnn)\
**Post date:** [July 24, 2024, 4:02pm UTC](https://forum.knime.com/t/regex-extractor-node/81290/4 "2024-07-24T16:02:42Z")

</div>

Hope this is a better understanding  
@rfeigel

---

<div class="post-metadata">

**Author:** ![rfeigel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rfeigel](https://forum.knime.com/u/rfeigel)\
**Post date:** [July 24, 2024, 4:30pm UTC](https://forum.knime.com/t/regex-extractor-node/81290/5 "2024-07-24T16:30:59Z")

</div>

It would be a lot easier if you provided some sample data.

---

<div class="post-metadata">

**Author:** ![NabilEnn](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/n/59ef9b/32.png) [@NabilEnn](https://forum.knime.com/u/NabilEnn)\
**Post date:** [July 24, 2024, 5:12pm UTC](https://forum.knime.com/t/regex-extractor-node/81290/6 "2024-07-24T17:12:29Z")

</div>

It is confidential or else i would, for any instance i’m wondering how can i extract a line of text under a keyword, the keyword is always the same in every document. In python I will use a function to get text after 2 lines or 3 or whatever the case may be but im trying to figure out how to do that in knime using the regex extractor. I’m not sure if a lag column node will shift the regex down or im pretty confused how this would work as i entered this regex to extract one line under the word “Name” in the regex extractor but it didnt seem to work. Regex I tried was = (?\<=Name:\s\*).\*$  
@rfeigel

---

<div class="post-metadata">

**Author:** ![rfeigel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rfeigel](https://forum.knime.com/u/rfeigel)\
**Post date:** [July 24, 2024, 7:47pm UTC](https://forum.knime.com/t/regex-extractor-node/81290/7 "2024-07-24T19:47:33Z")

</div>

Share some dummy data with the format you have.

---

<div class="post-metadata">

**Author:** ![rfeigel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rfeigel](https://forum.knime.com/u/rfeigel)\
**Post date:** [July 26, 2024, 12:55am UTC](https://forum.knime.com/t/regex-extractor-node/81290/8 "2024-07-26T00:55:36Z")

</div>

Since you won’t share any sample data, I’m doing some guessing. This workflow is pretty crude but works with both: No Regex.

Name:  
John Doe

Name: John Doe

[Name Extractor.knwf](https://forum.knime.com/uploads/short-url/etqEKw3qj1hz2gC19YCHyqhlptc.knwf) (86.6 KB)  
 ![1](https://forum-cdn.knime.com/uploads/default/original/3X/4/1/41867566dc99d398be88a34b95d6d2d86dc244c0.jpeg)  
Input  
 ![2](https://forum-cdn.knime.com/uploads/default/original/3X/0/d/0d73b647e40a2a35021fe5411850e1439dc4daca.jpeg)  
Output  
 ![3](https://forum-cdn.knime.com/uploads/default/original/3X/1/e/1e89f07eeaf16114018f0301e4fae5f43c47b532.jpeg)

---

<div class="post-metadata">

**Author:** ![NabilEnn](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/n/59ef9b/32.png) [@NabilEnn](https://forum.knime.com/u/NabilEnn)\
**Post date:** [July 26, 2024, 2:25pm UTC](https://forum.knime.com/t/regex-extractor-node/81290/9 "2024-07-26T14:25:51Z")

</div>

im not sure how to make some dummy data. But the workflow would need regex because the name of the person im trying to extract may not be on the same line everytime… Is there anyway to use my regex to extract everything on the same line after the word “Name:” but to also take the exactly 1 line under the word “Name:”

---

<div class="post-metadata">

**Author:** ![rfeigel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rfeigel](https://forum.knime.com/u/rfeigel)\
**Post date:** [July 26, 2024, 2:54pm UTC](https://forum.knime.com/t/regex-extractor-node/81290/10 "2024-07-26T14:54:58Z")

</div>

Have you looked at my workflow? I think it does what you want. I can’t understand why you’re insisting on regex.

---

<div class="post-metadata">

**Author:** ![NabilEnn](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/n/59ef9b/32.png) [@NabilEnn](https://forum.knime.com/u/NabilEnn)\
**Post date:** [July 26, 2024, 8:29pm UTC](https://forum.knime.com/t/regex-extractor-node/81290/11 "2024-07-26T20:29:38Z")

</div>

Yes, because what if i have a bunch of files and the word “Name” is in a different row for each file.

---

<div class="post-metadata">

**Author:** ![rfeigel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rfeigel](https://forum.knime.com/u/rfeigel)\
**Post date:** [July 26, 2024, 11:21pm UTC](https://forum.knime.com/t/regex-extractor-node/81290/12 "2024-07-26T23:21:41Z")

</div>

I can’t help you without some sample data. Your description isn’t clear enough. What happens when you run my workflow?

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [July 27, 2024, 3:45am UTC](https://forum.knime.com/t/regex-extractor-node/81290/13 "2024-07-27T03:45:33Z")

</div>

> [@NabilEnn](#):
>
> would need rege

The new expression node does have Regex extraction functions. With knime you will have to double escape \ backslash.

> **[Expression](https://hub.knime.com/knime/extensions/org.knime.features.base.expressions/latest/org.knime.base.expressions.node.ExpressionNodeFactory)**
>
> The KNIME Expression node enables generic row-by-row data manipulation within KNIME workflows. Data Access: The expression is evaluated for each row in the inp…

One example in [this workflow](https://hub.knime.com/-/spaces/-/~wB3gLYsvKkPrIo2I/current-state/):

![IMG_8630](https://forum-cdn.knime.com/uploads/default/original/3X/1/1/11f4afcd95a3fe0a9d3fb6ad43e0f815a9258523.jpeg)

Regarding the syntax you could employ ChatGPT and also may want to think about edge cases.

---

<div class="post-metadata">

**Author:** ![rfeigel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rfeigel](https://forum.knime.com/u/rfeigel)\
**Post date:** [July 27, 2024, 4:00pm UTC](https://forum.knime.com/t/regex-extractor-node/81290/14 "2024-07-27T16:00:15Z")

</div>

Here’s a workflow with Regex. I don’t think it does anything that my first workflow didn’t. I still don’t completely understand your data configuration.  
[Name Extractor rev 1.knwf](https://forum.knime.com/uploads/short-url/w3kGXhSKCrP0eDUgdkNPLbs3i6i.knwf) (99.7 KB)

---

<div class="post-metadata">

**Author:** ![NabilEnn](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/n/59ef9b/32.png) [@NabilEnn](https://forum.knime.com/u/NabilEnn)\
**Post date:** [July 29, 2024, 1:56pm UTC](https://forum.knime.com/t/regex-extractor-node/81290/15 "2024-07-29T13:56:10Z")

</div>

@mlauber71 is there a regex expression that will extract 2 lines of text after a keyword?. the texts I’m trying to extract are in a line, but not always on the same line. and not in a column. @rfeigel.  
Sorry about not providing dummy data, i can give you a better example.  
Med Facility  
ibfaiuwebflwaiuf  
Name:  
John Doe

Now if i were to paste that text in table creator then it would be easy to just extract by row filter, but i have to parse the pdf files. So im pasting the file paths in tablke creator and then outputing to tika by url. Then parsing the file, so i would then need regex expression, because the name im trying to extract out of every file may not be on the same line. Unless there is another way. Let me know when anyone gets a chance, thanks for your contribution/help so far!

---

<div class="post-metadata">

**Author:** ![rfeigel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rfeigel](https://forum.knime.com/u/rfeigel)\
**Post date:** [July 29, 2024, 2:46pm UTC](https://forum.knime.com/t/regex-extractor-node/81290/16 "2024-07-29T14:46:44Z")

</div>

Do you still have cases where the name is on a line like this “Name: John Doe” ?

---

<div class="post-metadata">

**Author:** ![NabilEnn](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/n/59ef9b/32.png) [@NabilEnn](https://forum.knime.com/u/NabilEnn)\
**Post date:** [July 29, 2024, 3:33pm UTC](https://forum.knime.com/t/regex-extractor-node/81290/17 "2024-07-29T15:33:39Z")

</div>

@rfeigel yes correct

---

<div class="post-metadata">

**Author:** ![NabilEnn](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/n/59ef9b/32.png) [@NabilEnn](https://forum.knime.com/u/NabilEnn)\
**Post date:** [July 29, 2024, 8:28pm UTC](https://forum.knime.com/t/regex-extractor-node/81290/18 "2024-07-29T20:28:56Z")

</div>

when its like this “Name: John Doe” i use this regex “Name:(.\*)” which works but then when the name is like  
“Name:  
John Doe”  
it wont extract it because the regex is to extract everything on the same line.  
@rfeigel

---

<div class="post-metadata">

**Author:** ![rfeigel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rfeigel](https://forum.knime.com/u/rfeigel)\
**Post date:** [July 30, 2024, 4:26am UTC](https://forum.knime.com/t/regex-extractor-node/81290/19 "2024-07-30T04:26:09Z")

</div>

Try this. The bottom workflow handles both single and two line names.

> **[Name Extractor rev 2 – rfeigel](https://hub.knime.com/rfeigel/spaces/Public/Name%20Extractor%20rev%202~SGqX80ABlt5GJOpa/current-state)**
>
> Solutions for data science: find workflows, nodes and components, and collaborate in spaces.

---

<div class="post-metadata">

**Author:** ![NabilEnn](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/n/59ef9b/32.png) [@NabilEnn](https://forum.knime.com/u/NabilEnn)\
**Post date:** [July 30, 2024, 2:27pm UTC](https://forum.knime.com/t/regex-extractor-node/81290/20 "2024-07-30T14:27:18Z")

</div>

[Untitled 1.pdf](https://forum.knime.com/uploads/short-url/3foLFFsioRY3P9Sme3YtMME49Z8.pdf) (17.2 KB)

I have attached a dummy file here. Now just a reminder, this file can easily be done with just row filter to extract the name. But I have a lot of files where the name is not on the same row. I tried your workflow, it does work when you just paste the text in the table creator but i couldn’t get it to work when i added a file path and tika by url to parse it. See if you could access the dummy file, it has the keyword “Name:” and then “John Doe” under it, when you get a chance see if you can extract the “John Doe” with regex.

[Next page](https://forum.knime.com/t/regex-extractor-node/81290.md?page=2)
