Regex Question

J

JM

Hi,

I am pretty new to regex, and I am trying to find a why to do:

1) I have a paragraph "... the black monkey (gamma5) is the one who develop
the first inmunoresitance to alpha-23 also there..."
2) I need to match everything (from some point) until a certain word
(example until alpha-23).
3) I have try to use the next regular expression: ".*alpha-23 " but since
there are other ocurrence of "alpha-23" it try to match everything.

My question:

Is there any command that allow me to match everythin "until" a certain
word?.
Something like [^RH] will match until the first occurrence of R or H but
instead of R or H I need R "followed by" H

Thanks,

Jaime
 
T

Thomas T. Veldhouse

JM said:
Hi,

I am pretty new to regex, and I am trying to find a why to do:

1) I have a paragraph "... the black monkey (gamma5) is the one who develop
the first inmunoresitance to alpha-23 also there..."
2) I need to match everything (from some point) until a certain word
(example until alpha-23).
3) I have try to use the next regular expression: ".*alpha-23 " but since
there are other ocurrence of "alpha-23" it try to match everything.

"(^.*?alpha-23)(.*)"

The first group will match what you are looking for and all the rest will be
in the second group.

You can name them like this:

"(?<group1>^.*?alpha-23)(?<group2>.*)"

And then access like this:

Regex regex = new Regex("(?<group1>^.*?alpha-23)(?<group2>.*)");
Match match = regex.Match(inputString);
if (match.Success)
{
string group1Text = match.Groups["group1"].Value;

// do something with the text
}


My question:

Is there any command that allow me to match everythin "until" a certain
word?.
Something like [^RH] will match until the first occurrence of R or H but
instead of R or H I need R "followed by" H

Sounds like:

"^.*?RH"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top