# Regex between first and second "-"

**URL:** <https://forum.knime.com/t/regex-between-first-and-second/67982>\
**Category:** KNIME Analytics Platform\
**Tags:** regex\
**Created:** [June 1, 2023, 11:30am UTC](https://forum.knime.com/t/regex-between-first-and-second/67982 "2023-06-01T11:30:37Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![AlexanderFillbrunn](https://forum-cdn.knime.com/user_avatar/forum.knime.com/alexanderfillbrunn/32/357_2.png) [@AlexanderFillbrunn](https://forum.knime.com/u/AlexanderFillbrunn)\
**Post date:** [June 2, 2023, 11:25am UTC](https://forum.knime.com/t/regex-between-first-and-second/67982/7 "2023-06-02T11:25:06Z")

</div>

Hey,  
Good point! Now I think I have found a one-node-solution, but it is not very pretty. You can use this expression in the String Manipulation node to handle all 4 cases:

```
regexReplace($Data$, "^[^-]+-([^-]+).*", "$1") == $Data$ ? "" : regexReplace($Data$, "^[^-]+-([^-]+).*", "$1")

```

Using the Java ternary operator was inspired by [this post](https://forum.knime.com/t/fun-with-string-manipulations-undocumented-features/66111). But of course it is a bit ugly that we need the regexReplace twice.  
Alexander

---

_[View the full topic](https://forum.knime.com/t/regex-between-first-and-second/67982)._
