Nick Thorpe
Nick Thorpe

Reputation: 83

Regex: include some characters but not others

For the string abc-1234_56678-123_6y1, I want to only extract the trailing _6yz.

I need the selection to

  1. start with an "_"
  2. include at least one letter
  3. not include a "-" Every attempt I have made returns "_56678-123_6y1". Here's what I was the most confident in _.[\p{L}].([^-]) where I search for substrings that do not contain a "-".

What am I missing?

Upvotes: 0

Views: 44

Answers (1)

Nick Thorpe
Nick Thorpe

Reputation: 83

I was at this problem longer than I'd like to admit, then stumbled on to the answer while doing another query. The final answer for my problem is

_[^-]+([\p{L}].*)

Henry Woody's answer is also good aside from the condition that my selection must contain a letter.

Upvotes: 1

Related Questions