‏إظهار الرسائل ذات التسميات replace. إظهار كافة الرسائل
‏إظهار الرسائل ذات التسميات replace. إظهار كافة الرسائل

الثلاثاء، 24 ديسمبر 2013

How to replace text between two XML tags using jQuery or JavaScript?

I have a XML mark-up/code like the following. I want to replace the text inside one of the tags (in this case ...) using JavaScript or jQuery.

A new beginning Stuff here...

The source is inside a textarea. I have the following code, but it is obviously not doing what I want.

code=$("xml-code").val(); // content of XML sourcenewBegin = "The same old beginning"; // new text inside tagsnewBegin = ""+newBegin +""; code=code.replace("",newBegin); // replace content

This is just appending to the existing text inside the begin tags. I have a feeling this can be done only using Regex, but unfortunately I have no idea how to do it.


View the original article here

الجمعة، 20 ديسمبر 2013

How to replace only IP in url string in file

You will first need to read the files content. Then you could use a regular expression that matches the ip address (e.g. \d+\.\d+\.\d+\.\d+) and replace it with the new one. When you've done that write it back in the file again.

Here is a regex tester: http://www.regexplanet.com/advanced/java/index.html

Here a tutorial of how to read and write files: http://www.java-samples.com/showtutorial.php?tutorialid=392


View the original article here