Reinhardt
Reinhardt

Reputation: 453

Regex matching group

I have the following pattern format of text:

The @DaysInMonth is gets on how many days are there based on the selected month, @FirstTitle and the @SecondTitle is alphanumeric.

I tried with the following:

[\1(?<DaysInMonth>\d\s+) (?<FirstTitle>[\w\s \]+)\] (?<SecondTitle>[\w\s \]+)$]

But it didn't seems to working. The matches character is 53 characters. [Link]

How can I solve this?

Edit after @baddger964 answer:

I want to use in my application like this:

private Regex _regex = null;

string value = "[1/30 Development In Progress] Development In Progress";

_regex = new Regex(@"\[\d+\/(?<DaysInMonth>\d+)\s(?<FirstTitle>[\w\s]+)\]\s(?<SecondTitle>[\w\s]+)").Match(value);

string value1 = _regex.Groups["DaysInMonth"].Value;
string value2 = _regex.Groups["FirstTitle"].Value;
string value3 = _regex.Groups["SecondTitle"].Value;

Your answer much appreciated.

Thank you.

Upvotes: 2

Views: 113

Answers (2)

baddger964
baddger964

Reputation: 1227

Maybe you can use this :

\[\d+\/(?<DaysInMonth>\d+)\s(?<FirstTitle>[\w\s]+)\]\s(?<SecondTitle>[\w\s]+)

for note :

\1 => dont escape the "1" because \1 match the same thing as the last defined match group.

[ => ou have to escape this \[ because with [ you create a set of caracters

so your regex :

[\1(?<DaysInMonth>\d\s+) (?<FirstTitle>[\w\s \]+)\] (?<SecondTitle>[\w\s \]+)$]

says : i want match one caracter from this set of caracter :

\1(?<DaysInMonth>\d\s+) (?<FirstTitle>[\w\s \]+)\] (?<SecondTitle>[\w\s \]+)$

Upvotes: 2

Lucas Carnevalli
Lucas Carnevalli

Reputation: 62

Like this? Here is an example of a normal regex if you interesse.

https://regex101.com/r/wLBj7Z/1

Upvotes: 0

Related Questions