List Info

Thread: replacing variable with same variable




replacing variable with same variable
user name
2006-10-11 15:13:26
I have a perl script where I match on phrase to add
something after
that phrase:
$line=~s/PILOT_INC=4,/PILOT_INC=4, NGHBR_SRCH_MODE = 0,/g;

However, the "4" can be variable, say, anything
between 2 and 8.

I'd like to do something like this:
$line=~s/PILOT_INC=d,/PILOT_INC=d, NGHBR_SRCH_MODE = 0,/g;
Of course this won't work.

Do I need to first save the number into a variable and then
put that
variable into the regex replace phrase or can it be done
within the
global search and replace regex line above?

regards, David


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://grou
ps-beta.google.com/group/regex
-~----------~----~----~----~------~----~------~--~---

replacing variable with same variable
user name
2006-10-13 21:45:59

David wrote:
> I have a perl script where I match on phrase to add
something after
> that phrase:
> $line=~s/PILOT_INC=4,/PILOT_INC=4, NGHBR_SRCH_MODE =
0,/g;
>
> However, the "4" can be variable, say,
anything between 2 and 8.
>
> I'd like to do something like this:
> $line=~s/PILOT_INC=d,/PILOT_INC=d, NGHBR_SRCH_MODE =
0,/g;
> Of course this won't work.
>
> Do I need to first save the number into a variable and
then put that
> variable into the regex replace phrase or can it be
done within the
> global search and replace regex line above?
>
> regards, David

Or you can try the following:

$line=~s/PILOT_INC=([2-8]),/PILOT_INC=$1, NGHBR_SRCH_MODE =
0,/g;

Regards,
Manish


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://grou
ps-beta.google.com/group/regex
-~----------~----~----~----~------~----~------~--~---

replacing variable with same variable
user name
2006-10-16 18:37:12
Thanks, Manish.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://grou
ps-beta.google.com/group/regex
-~----------~----~----~----~------~----~------~--~---

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )