How would a regex look like when I search for this string:
before CAN be many comment lines --------"Encrypted" after must come a newline.
this does not seem to work:
Regex pattern = new Regex(@"^[-]*$[Encrypted][\n]");
what do I wrong?
How would a regex look like when I search for this string:
before CAN be many comment lines --------"Encrypted" after must come a newline.
this does not seem to work:
Regex pattern = new Regex(@"^[-]*$[Encrypted][\n]");
what do I wrong?
Try it without the square brackets and move the dollar $
to the end of the pattern. Ie:
Regex pattern = new Regex(@"^-*Encrypted$");
The square brackets is like an Or
statement. So [Encrypted]
is the same as saying: 'E' or 'n' or 'c' or 'r'.... or 'd'
.
The dollar symbol matches the end of the string.
The pattern you're searching for is not entirely clear to me, nor are the rest of the contents you're searching in, but if you're really just looking for "Encrypted" directly followed by only a newline then this is all you need to do:
Regex r = new Regex(@"Encrypted\n")
EDIT
Ok, comments seem to suggest that you're looking for zero or more occurences of "-", followed by "Encrypted", followed by newline. In that case the following will work.
Regex r = new Regex(@"-*Encrypted\n");
If there should be at least one "-" before "Encrypted", it will be
Regex r = new Regex(@"-+Encrypted\n");
I don't know specifically regex for c# but i thing you must not put the ^ because -'s are not at the begining of the line. And what the $ is doing in the middle.
So i would do in PCRE regex:
/-+"Encrypted" *\n/
That match one or more - followed by "Encryption" followed by 0 or more space followed by newline.
@Sanju
does this work :P
Regex pattern = new Regex(@"-*Encrypted\n");
for me it did! You have to remove the "^" char