How can I extract specific hours from a description?

I am trying to extract the number of hours from a column with different description formatting.

For example:
Technician - 14 hrs working on Monday Sep 18 2023
Sep 23 - Accrual 14 hrs working on plumbing

The descriptions all mention hrs but where they are in the description is different. Is there anyway to extract this?

Hi @vivianmpoon

A quick way to extract this information is by using a RegexExtractor node, available here in case you don’t have it yet:

You can use a positive lookahead with [0-9]+(?= hrs)

5 Likes

I don’t have the RegexExtractor and I’m trying to download the NodePit to get it but I’m getting this error.

image

Do you know if there are any ways to fix this?

Try https://download.nodepit.com/4.7 and press reload for safety.

1 Like

I’m still getting the same error

@vivianmpoon
The string manipulation node also supports regex (e.g. regexReplace) which you can use
sth like this (you might need to tweak it)

regexReplace($column1$,".*?\\s([0-9]+)\\shrs.*" ,"$1" )
br

2 Likes

If your company blocks access to the update site URL, which is the most likely reason for that, you can also install from a ZIP’ed update site.

Instructions for that are available here:

Note that installing directly from update site is the preferred way, and we only recommend the ZIP as a workaround for the issue described above.

2 Likes

@qqilihq
is regex extractor available in new knime 5.x?

1 Like

Yes, Palladian is available for KNIME 5.x :slight_smile:

2 Likes

I was able to download it this way. Thank you!

1 Like

Is there another way to do this when there are decimals in the hours? I have some that are 8.25 hrs for example.

You can extend the regex as follows to capture full hours and such with decimals:

[0-9]+(?:\.[0-9]+)?(?= hrs)
4 Likes

For some reason it’s not working?

To cover both hrs and Hrs, either set the “case insensitive” flag in the node’s options or modify the expression as follows:

[0-9]+(?:\.[0-9]+)?(?= [hH]rs)
4 Likes

Thanks so much! This worked for me :smiley:

1 Like

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