1

I need to find fisrt, second and third substring from string like "One - Two-Two- Three-Three" by splitting them only by " - " (with first and last characters being spaces).

I can split them by "-", like:

regexp_substr(teenimi, '[^-]+', 1, 1 ) as a,
regexp_substr(teenimi, '[^-]+', 1, 2 ) as b,
regexp_substr(teenimi, '[^-]+', 1, 3 ) as c

which gives me result like: One // Two // Two, but I need One // Two-Two // Three-Three

1 Answer 1

2

You may use a regex like

[^- ]+(-[^- ]+)*

See the regex demo

It will match

  • [^- ]+ - 1 or more chars other than - and space
  • (-[^- ]+)* - zero or more sequences of
    • - - a hyphen
    • [^- ]+ - see above.

Basically, it will match - that has no space on either side and non-whitespace characters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.