how to replace "@" in a string

Posted on 2004-11-15
Medium Priority
Last Modified: 2013-12-25
how to replace "@" in a string with "\@" without using any modules in cgi script?
Question by:jiniasp

Accepted Solution

PaulS_III earned 750 total points
ID: 12583763
Assuming you have a variable holding the text that contains the "@" I would do somthing like this:

var =~s/\@/\\\@/g;

Since Perl (I am assuming) interprets the "@" as an array you would need to escape it for the regex to first find it and then replace it with the escaped version so the \@ used above will allow the @ to be found then the \\\@ is the escaped version.  I do believe this will work as expected.

LVL 48

Expert Comment

ID: 12587687
I'll assume you are talking about a Perl/CGI script, so you can do:

$string =~ s/@/\\@/;

Why do you want to do this anyway?

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question