Re: Write multiple backslashes
| From: | Ryan Pallas | Date: | Wed, 08 Mar 2017 13:40:09 +0000 |
| Subject: | Re: Write multiple backslashes | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-326015@lists.php.net to get a copy of this message | ||
On Mar 8, 2017 6:27 AM, "Jason Pruim" <pruimj@gmail.com> wrote:
Sent from my iPhone
> On Mar 8, 2017, at 4:48 AM, Danny <mynixmail@gmail.com> wrote:
>
> Hi,
>
> I have a file in which I need to interchange two regular expressions
every hour
> depending on what data will be processed. In other words, I will replace
the one
> regular expression with the other (they are never together in the same
file).
> This file is a configuration file for attatched hardware (not written by
myself
> but by the hardware manufacturer).
>
> Below is what it should look like in the file:
> IGNORE_TMP=^()$
> or
> IGNORE_TMP=^(\\*.*\\*)$" (Yes, this one has 2 backslashes)
>
> Now, the first regular expression I can write to the file like this with
no
> problems:
> $first_regexp = "/IGNORE_TMP=\\^\\(\\)\\$/" ;
> which will give me:
> IGNORE_TMP=^()$.
>
> However, I cannot seem to get it right to write the second regular
expression
> correctly to get 2 backlashes. I can get 1 with no problem:
> $second_regexp = "IGNORE_TMP=^(\\*.*\\*)$" ;
I'm no regard expert but don't you have to escape it for each one?
Something like $second_rexexp = "ignore_tmp=^(\\\\*.*\\\\*)$";
I could be way off base though...
Yes that's true but only because it is a double quoted string, meaning
backslashes are treated as escape sequences.
You could also just use a single quoted string.
$second_regexp = 'IGNORE_TMP=^(\\*.*\\*)$';
> ### Here is just the rest of the code for reference ###
> $block_file = file_get_contents ( $tmp_file ) ;
> $block_regexp = preg_replace ( $old_block, $new_block, $block_file ) ;
> file_put_contents ( $tmp_file, $block_regexp ) ;
> $remove_blank_lines = exec ( 'sed -i "/^[[:space:]]*$/d"
/etc/scripts/motor_control/temperature.conf' ) ;
> #######################################################
>
> Any pointers?
>
> Thank you
>
> Danny
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php