Regular expression (huh?)
Posted: Thu Oct 13, 2005 7:49 pm
The term "regular expression" has always rather bemused me, as I see nothing regular about it at all. The whole concept is something that I have simply never been able to get my head wrapped around at all. Fortunately, one can write code without it. Maybe the code would be better with it, but....
Anyway, I am adapting a product that seems to require a preg_match and I'm not sure why. It uses this javascript:
which doesn't work unless the text is first translated with:
But that removes all of the newlines from the text, which is a bummer. Since the whole function could be written in sanskrit, I have no idea how to deal with the situation.
In the first parameter the forward slashes are delimiters, I got that much, but what is all the rest? And what is the replacement string? Is $1 some kind of constant? Because I see it nowhere in the code. Will the js not work if there are newlines?
I will take all the help I can get, here.
Anyway, I am adapting a product that seems to require a preg_match and I'm not sure why. It uses this javascript:
Code: Select all
<script language="JavaScript">
<!--
function WriteBack(form_name,field_name,text)
{
opener.document[form_name][field_name].value = text;
}
-->
</script>Code: Select all
$str = preg_replace("/('|\"|\\\\|\r|\n)/", "\\\\\$1", $str);In the first parameter the forward slashes are delimiters, I got that much, but what is all the rest? And what is the replacement string? Is $1 some kind of constant? Because I see it nowhere in the code. Will the js not work if there are newlines?
I will take all the help I can get, here.