Page 1 of 1

Using mulitple wildcard for replace

Posted: Mon Feb 05, 2007 11:48 pm
by predaina
Hi,

Thank you for your help on my last question. I was doing fine until this.

I want to capture the author name from the <p>by: fname lname</p> line and place into the Author meta tag.

My existing html document: (the jave code is one line and no special characters).


<meta name="Author" content="someone @ the-internet.com" />
<meta name="Robots" content="noindex,nofollow" />
<link rel="stylesheet" href="../stylesheet.css" type="text/css" />
</head>
<script language="JavaScript1.2">
function run()
{
some java code here
}
</script>
<body>
<!-- Article Start -->
<h1>10 Article Writing Quirks</h1>
<!-- Author -->
<p>by: Nicholas Dixon</p>
<p>Much has been touted about... rest of the file



This is the RE I tried:

search for: <meta name="Author" content="(.*)" />\r\n(.*)<!-- Author -->\r\n<p>by: (.*)</p>\r\n

replace with: <meta name="Author" content="$3" />\r\n$2<!-- Author -->\r\n<p>by: $3</p>\r\n


The result is:
<meta name="Author" content="Nicholas Dixon</p>
<p>Much has been touted about... rest of the file


I tried modifiers S,G and S,G,M.

You know, I turned off the S and M modifier and it worked! So no need to reply - thanks

Thanks in advance.

Re: Using mulitple wildcard for replace

Posted: Tue Feb 06, 2007 3:14 pm
by Abacre
predaina wrote:This is the RE I tried:

search for: <meta name="Author" content="(.*)" />\r\n(.*)<!-- Author -->\r\n<p>by: (.*)</p>\r\n

replace with: <meta name="Author" content="$3" />\r\n$2<!-- Author -->\r\n<p>by: $3</p>\r\n


The result is:
<meta name="Author" content="Nicholas Dixon</p>
<p>Much has been touted about... rest of the file



I have verified your RE: it's correct and it's working.
The only question is to setup correct modifiers:

State of Modifier M: does not matter for your case. The same for
modifiers: I, X and E.

But you have to turn on Modifier S. So .* in \r\n(.*)<!-- Author -->
will be used across several lines of text.

And you have to turn off Modifier G. That's why you have got the
result (text in red above). Because it was taken in greedy mode.

Posted: Tue Feb 06, 2007 4:08 pm
by predaina
Thank you again Roman, I am slowly starting to understand how this tool can be very powerful (and dangerous if you're not watching). 8)

Best regards!

Posted: Tue Feb 06, 2007 5:33 pm
by Abacre
It can be even more powerful with Modifier E turned on.
You may convert text into upper or lower case, wrap text, compare text
and execute some other useful functions.