Keeping dash in a string

Hi, how do i keep dash and numbers in a string?

From:
71110-20 POS (DEPT) DAY END GST

Manage to get using regexReplace($Account$,“[^0-9.-.]”,“”):
7111020

But I want:
71110-20

Thank you in advance.

Hi @lywei

This should suffice: regexReplace($Account$,“[aA-zZ]|\\s|\\(|\\)”,“”)

  • Replace any upper or lowercase letter → [aA-zZ]
  • Replace blank spaces → \\s
  • Replace parenthesis → \\( | \\)

2 Likes

Hi @eamendola ,

I am seeing the following error:

Is there any alternative?

Thank you.

Hi @lywei

regexReplace($Account$, "^(\d+-\d+).*$", "$1")

BR

Hi @gonhaddock ,

Hmm, doesn’t seem to work:

Thank you.

1 Like

Oh!

image

Ok, the right syntax in KNIME must be:

regexReplace($Account$, "^(\\d+-\\d+).*$", "$1")

Scape bars are necessary

BR

1 Like

It’s a conversion of the double quotes on the website, please type the double quotes instead.

1 Like

Hi @gonhaddock ,

oo, it works. But is it possible to keep the numbers for these too?

Thank you.

@lywei

regexReplace($Account$, "^([0-9-.]+).*$", "$1")

BR

Hi @lywei , you can try this:
regexReplace($Account$,"[aA-zZ]|\\s|\\(|\\)","")