Tahir,
Although the wildcard helps, there are situations where it can’t be used. Here’s an example.
The attached document (Fresh.docx) contains the following text:
"Blah blah blah
This is my first line
User1 signature
This is my first line
User2 signature
Blah blah blah
"
Let’s say I want to replace “This is my first line\rUser2 signature” with some text. I can’t use “This is my first line(.*?)User2 signature” as it will grab the User1 signature line. So I adjusted regex to do “This is my first line(\r\n|\r|\n|\v)User2 signature” but that doesn’t seam to work. (Currently on 17.3.0)
Here’s the code I am using:
var doc = new Aspose.Words.Document(req.DocumentFilePath);
if (doc.Range.Replace(new Regex("This is my first line(\r\n|\r|\n|\v)User2 signature"), RegexOptions.Singleline), "My replacement line", new FindReplaceOptions()) > 0)
{
Console.WriteLine("Match found & replaced");
}
And here’s a working example: http://regexr.com/3fjbj
The other interesting part is that trying the .NET Regex.Match returns success so is this a bug?
Console.WriteLine($"Success1: {Regex.Match("Blah blah blah\rThis is my first line\rUser1 signature\rThis is my first line\rUser2 signature\rBlah blah blah\r", "This is my first line(\r\n|\r|\n|\v)User2 signature").Success}");
Console.WriteLine($"Success2: {Regex.Match("Blah blah blah\r\nThis is my first line\r\nUser1 signature\r\nThis is my first line\r\nUser2 signature\r\nBlah blah blah\r\n", "This is my first line(\r\n|\r|\n|\v)User2 signature").Success}");
Thanks