detect samepattern

  • Thread starter Thread starter Fyne
  • Start date Start date
F

Fyne

I have a lot of string data, I want to know if data_i is subtring of
data_{i+1}
a simple case, data1=atcgat*gatta, data2=atcgat*tsgatgat, they both
separated by an asterisk

I did


Regex separator=new Regex(@"^(\**)$");
then Ismatch() to check it

but this is incorrect, could you help me ? i am very new to C# please
help me

Thanks
 
Fyne said:
I have a lot of string data, I want to know if data_i is subtring of
data_{i+1}
a simple case, data1=atcgat*gatta, data2=atcgat*tsgatgat, they both
separated by an asterisk

I did


Regex separator=new Regex(@"^(\**)$");

That regex matches a line containing zero or more asterisks

Something like this

Regex separator=new Regex(@"^.*\*.*$");

will match an optional substring, one asterisk and another optional
substring, i.e. any string containing an asterisk. However, if the string
contains more than one asterisk, it will (probably) match on the last
asterisk.

You can tighten this up a bit:

Regex separator=new Regex(@"^[^\*]*\*[^\*]*$");

This will match a string that contains exactly one asterisk, optionally
surrounded by non-asterisk characters.
but this is incorrect, could you help me ? i am very new to C#

Hmm, I think it's more like you're new to regular expressions. Take a look
at Regex Coach at http://weitz.de/regex-coach/

Ebbe
 

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

Back
Top