0

There is a question here:

Regex Match.Value returning entire value, not the matched groups

But my question is different

I use

var match = _regex.Match(inputString);
return match.Value;

And I would like to cope without referring to groups by index. Is it possible?

I would like to have a match which does not return #WORD from string #WORD "SOMEWORD"

Pattern: ^#WORD(.+)$

Input: #WORD "SOMEWORD"

returns #WORD "SOMEWORD"

I need only "SOMEWORD"

Dmitry Dyachkov
  • 1,715
  • 2
  • 19
  • 46
  • You can turn your capture group into named `(?.+)` and use [this](https://stackoverflow.com/q/906493/4685428) answer. Or just refer your group by index (1 in your case) – Aleks Andreev Feb 22 '19 at 12:11
  • You already captured the part, access it with `match.Groups[1].Value` or - if you need to trim it - `match.Groups[1].Value.Trim()`. – Wiktor Stribiżew Feb 22 '19 at 12:12

1 Answers1

-1

you can use

(?<=^#WORD ")\w+(?="$)

Regexr

Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72