Regex Problem

Fer Trob 1 Reputation point
2021-05-04T23:29:33.9+00:00

Hello, I have a question in Regex that I believe is easy to solve, anybody can help me?

I need to get the first 3 characters of that string ("newtest-test"), the dash and the 2 characters after the dash (like that "new-te").
I use this regex "\w{3}-\w{2}" but return "est-te". What's wrong?

Azure Site Recovery
Azure Site Recovery
An Azure native disaster recovery service. Previously known as Microsoft Azure Hyper-V Recovery Manager.
636 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Henri 6 Reputation points
    2021-06-10T23:57:39.877+00:00

    You specified "\w{3}-\w{2}", which says to take 3 word characters followed by a dash followed by 2 word characters. "est-te" seems right. You might need something like "(\w{3})\w*-(\w{2})". You would need to combine the groups in the matches.

    0 comments No comments