0

Hi guys i have java scripts as follows

His acquaintance with Elizabeth was very trifling.&quot;</p>\n<P class=&quot;Sx0x1&quot;>&quot;To be sure, Lizzy,&quot; said her aunt, &quot;he is not so handsome as Wickham; or, rather, he has not Wickham\'s countenance, for his features are perfectly good. But how came you to tell me that he was so disagreeable?&quot;</p>\n<P>

I changed and replaced everything other than 'Wickham\'s '.The problem here is that when i use regex it only i dentifies ' but not the \ .I dont know if it is because this is a java script .Can anyone help me with this .thanks

4
Contributors
9
Replies
10
Views
6 Years
Discussion Span
Last Post by sadhawan
Featured Replies
  • As well as escaping the escape character as shown above you can use a string literal to prevent the [icode]\[/icode] being treated as an escape character: [icode]@"\'"[/icode] Read More

0

I'm not sure what it is you are trying to achieve : /
That isnt Java script..its a segment of html. What are you trying to m,atch with your regex?
Post some code so we can see what you're trying to do

0
private string processtext(string text)
        {



            string rep2 = "";
            string rep3 = "";
            string rep4 = "";
            text = text.Replace("\'", "''");
            text = text.Replace("’", "'");
            text = text.Replace("'", "''");
            text = Regex.Replace(text, "<(.|\n)*?>", string.Empty);

            text = text.Replace("<", "");
            text = text.Replace(">", "");
            text = text.Replace("&quot;", "");
            text = text.Replace("section_title=", "");
            text = text.Replace("section_txt=", "");
            Match a = Regex.Match(text, "section_title='(?<TITLE>.*)'");
            Match k = Regex.Match(text, "prev=[0-9][0-9]");
            rep3 = k.Groups[0].Value;
            if (rep3 != "")
            {
                text = text.Replace(rep3, "");
            }
            text = text.Replace("prev=", "");
            Match l = Regex.Match(text, "Chapter [0-9][0-9]");
            rep4 = l.Groups[0].Value;
            if (rep4 != "")
            {
                text = text.Replace(rep4, "");
            }
            rep2 = a.Groups[1].Value;
            if (rep2 == "")
            {
                return text;
            }
            else
            {

                text = text.Replace(rep2, "");

                return text;
            }
        }

this code will replace the ' but not \
if you read line number line that line does not do anything for me .If i try to replace just \ it will give me error if i try '\ it wont do anything

Edited by sadhawan: wrong

0

As nick indicated (but I'll expand on a bit) if you're trying to match the character '\' you need to write it as '\\'. This is because '\' is considered part of an escape sequence when identifying characters that are otherwise reserved for use within your coding.

For more information on escape sequences check here.

Hope this helps :) Please remember to mark as solved once your issue is resolved.

Edit: Darn you Ryshad you beat me to the edit :P was about to include the @"\'" option then saw your post haha

Edited by Lusiphur: n/a

1

As well as escaping the escape character as shown above you can use a string literal to prevent the \ being treated as an escape character: @"\'"

0

thanks guys that helped and how would you get rid of " sign .

0

More or less same thing applies, " can be written as '\"' or @'"' or if presented in it's alternate form @"&quot;".

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.