Questions tagged [replace]

The process of substitution involves looking for a specific sequence within a given string and exchanging it with an alternative series of characters.

Eliminate the commas in the JSON string except for the commas that separate arrays

I am facing an issue with stringified JSON data that includes commas in the description fields which causes the AJAX post to fail when there are apostrophes or commas present. How can I modify the output of var test = JSON.stringify(data)? The current ...

Tips for swapping out a specific string in an HTML webpage with a different string using JavaScript

For my HTML website, I am trying to replace one string with another using JavaScript. Specifically, within the nodeList "AuthorList," there is a string called "Test String" that needs to be changed to "new test." I have attempted various modifications of ...

Utilize PHP to transform various forms of smart quotes

I have been working on a function to convert all types of smart quotes to regular quotes within text. However, the function I have put together still appears to be lacking proper support and design. How can I successfully convert all quote characters? fun ...

Utilizing jQuery to dynamically alter image src based on browser resize

I am working on a project where I have two images of different sizes - one for screens smaller than 759px and another for screens larger than 759px. My goal is to dynamically change the image source based on the window width. While I have successfully ach ...

substitute tags

Is there a way to change the tagName of a tag using jQuery? For example, if I have an HTML document and I want to replace all 'fieldset' with 'div'. Any suggestions would be appreciated! ...

What is the best way to convert integer values in pandas from having a "," for thousands to just a regular integer without ","?

I have a large dataframe with integers and floats inside. Some of the values exceed one thousand, which causes errors when trying to use them as integers. For example: A B C 0 1,598 65.79 79 1 -300 46.90 ...

Rearrange an array of names from the format "last, first" to "first last"

I want to switch the first name and last name positions within an array of names. $names = [ "barira, stefan", "cikka, maria", "luppo, martin ", "bill, sebastian" ]; The desired output should look li ...

Avoiding certain characters in elasticsearch for indexing

Utilizing the elasticsearch python client to execute queries on our self-hosted elasticsearch instance has been quite helpful. I recently discovered that it is necessary to escape certain characters, such as: + - && || ! ( ) { } [ ] ^ " ~ * ? : ...

Substitute the content within an <li> tag

Is there a way to replace or entirely remove - undefined without using substr()? The value of 'name' is dynamic and constantly changing. Any suggestions would be greatly appreciated. <li>name - undefined</li> <li>name - undefined</li& ...

How to strip HTML tags from a string in PHP while still showing them?

Let's explore the functionality of strip_tags(). strip_tags("<b>TEXT</b>"); The result will be: TEXT But what if I want to keep the tags visible without their effect? The output would look like this: <b>TEXT</b> Is i ...

Transforming values in a 2-dimensional array from strings to numerical data

Data From External Source Hello there, I've been utilizing the read_csv function in Python to pull data from a specified URL. The dataset I'm working with contains a column filled with character/string values, while the remaining columns are co ...

Is there a PHP function that can eliminate or substitute all individual characters in a string?

Looking for a PHP function that can eliminate (or substitute) any individual characters within a string. "Hello W X Y Z World" -> "Hello World" Any suggestions? ...

Eliminate consecutive repetitions of a specific character within a string

I'm trying to find a more efficient way to eliminate consecutive occurrences of '.' and replace them with just one in Python. This is the code I currently have: # remove multiple occurrences of '.' string = "FOO...BAR......FOO..BA ...

What is preventing me from replacing backslashes in a string that contains double quotes with the replace function?

# When dealing with strings containing backslashes and double quotes, the backslash cannot be replaced text = 'Sleep Profile will compare a user\'s trends to what\'s typical for "their" age' text.replace('\ ...

Is it possible to insert a character before a particular word, while also replacing a character in the middle of that word using the .replace method in JavaScript?

I have a script that is able to replace special characters with other characters, but I am looking to enhance it by adding an additional character before the word. For instance, Let's say I start with the word: "zài" and currently change it to: "zai ...

Replace Euro symbols in JavaScript Regexp with grouping

Need assistance creating a Regex pattern for &#8203; € 14,50. After the replacement is completed, only 14,50 Can anyone provide guidance? ...

Search and Swap content on Page using jQuery Array

Seeking help with a find and replace operation using jQuery on an array of characters. The original array consists of the following symbols: var f = ['“','â€','‘'','’','…', ...

PHP Chaining... It's so confusing to me!

I am experimenting with creating a chaining function to manipulate strings retrieved from an XML file. A single original string might require multiple replacements, some sourced from the XML file. Here is the conventional and messy wrapped approach: str ...

A guide to swapping text in a jQuery DOM component

In order to construct HTML from a jQuery ajax response, I prefer not to nest unsightly strings in javascript and avoid using templating scripts like mustache. Instead, I decided to utilize a template HTML with display: none as shown below: <div id="mes ...

What is the best method for using str.replace with regex=True in pandas for optimal efficiency?

Replacing dozens of strings across multiple columns in thousands of dataframes is currently taking hours due to inefficiency: for df in dfs: for col in columns: for key, value in replacement_strs.items(): df[col] = df[col].str.repla ...

Making multiple replacements in Python 3

I'm confused why my question was marked as "off topic." I am seeking programming assistance, not just a reference. Here is what I originally asked: I have a Python 3 script that sends HTML emails to a group of approximately 600 people. Sendmail seems unabl ...

Utilizing re.sub for modifying a pandas dataframe column while incorporating predefined restrictions - **Highly Beneficial**

This particular problem took some time for me to solve, as there were only bits and pieces of information on stack overflow. I wanted to share my solution in case anyone else is facing the same issue. Objective: 1- Modify strings in a entire pandas DataF ...

Customize documents using a template

I am faced with the task of removing a specific string from a large number of files. I'm looking for a way to efficiently accomplish this. Any suggestions on how to do this quickly? I prefer using a Python script, if possible. Thank you. ...

Efficient techniques for performing multiple string replacements in Python

What is an efficient method for performing multiple string replacements quickly? I'm attempting to insert spaces to abbreviate English words like he'll -> he 'll he's -> he 's we're -> we 're we've -> we 've Additionally, I am adding spaces ...

Is there a way to update a JSON Array in PHP by replacing the existing data with the new data?

I am working with a JSON file and have encountered an issue when trying to delete an object. Whenever I create a new array and write it back to the original JSON file, the new data ends up overwriting the entire file. I have tried using functions like arr ...

Loop through the <li> elements and use jQuery to update the text

Check out this HTML setup: <div class="mydiv"> <ul> <li>Text 1</li> <li>Text 2</li> </ul> <ul> <li>Text 3</li> <li>Text 4</li> </ul> <ul> < ...

How can I substitute the characters r'xb0' with r'260' in Python?

Is there a way to replace the characters r'\xb0' with r'\260' in a string? I have attempted it using the following code: test = u'\xb0C' test = test.encode('latin1') test = test.replace(r'\x ...

What are some examples of utilizing regex case conversion tokens (u l U L E) in PHP code?

Currently, I am trying to allow the user to input both the pattern and the replacement string for the PHP preg_replace function. The following code is functioning correctly: echo preg_replace('/(o)/', ', ${1}h!', 'hello'); // outputs 'hell, oh!' However ...

Matching a regular expression pattern at the beginning of a line for grouping strings

One of my tasks involves working with a markdown string that looks like this: var str = " # Title here Some body of text ## A subtitle ##There may be no space after the title hashtags Another body of text with a Twitter #hashtag in it"; My goal ...

Using regular expressions to replace strings in JavaScript

I have a URL that resembles the following http://localhost:12472/auctions/auction-12/lots/sort/something/12 I am looking to switch it out with this new URL http://localhost:12472/auctions/auction-12/lots/sort/somethingelse/12 Here, somethingelse can be ...

Using string replacement for effective search finding: Unleashing the power of substring matching

I have a method that adds an anchor tag for each instance of @something. The anchor tag links to a specific sub URL. Check out the code: private createAnchors(text: string) { return text.replace(/(@[^ @]+)/ig, '<a href="/home/user/$1">$1</a ...

Strip all non-alphabetic characters from a PHP string

Is there a way to eliminate all characters from a string except for letters? I need this feature for the first name input field. ...

Remove any empty spaces within a string that appears on the same line as a specific string

I'm a beginner in the world of Python and this marks my first attempt at coding. While I have come across similar issues while researching solutions, as a newcomer, I am struggling to adapt them to my specific needs. Therefore, I've taken the lib ...

What are the reasons behind the unexpected behavior of the replace() method in the newest Safari update?

What is causing the JS method replace() to behave incorrectly in Safari version 11.1 when using "$<" in the second argument? For example: "aaaXXXbbb".replace(/XXX/, '_before_$<_after_') The actual result is: "aaa$<_after_bbb" The ex ...

Unable to find the desired match with Regex

I'm attempting to use a regex to replace content within brackets, but I'm encountering an unexpected result. This is the text I'm trying to target: Foo (bar) Below is the regex pattern I am using: /(?=\().*(?=\))/ My expectati ...

Is it possible to reverse SEF URLs using jQuery?

I'm currently employing this script to generate SEF URL strings: Replace spaces with dashes and convert all letters to lowercase using JavaScript I've been curious if there exists a method to reverse this process using jQuery? For instance: th ...

Is it possible to change label text using CSS without referencing the element by its ID?

Here is a simple code snippet: <div class="delem"><label class="required" for="last_name">Full Name :</label><input id="fullname" type="text" name="fullname" value="" class="fullsize" required=""></div> <div class="delem" ...

Replacing a string in a textarea using Jquery

Trying to dynamically replace a string value in a textarea while typing into a textbox using jQuery. Utilizing the keypress event for this functionality. Any ideas on what could be causing issues with this example? <input type="text" id="textbox" /> ...

What is the best way to enclose specific characters in stringA within a tag whenever they appear in stringB?

For instance: $strA = 'What are you talking about?'; $strB = 'aeiou'; I want to enclose all vowels in strB that match any characters in strA with a <span>. Is there an efficient way to achieve this? echo tagMatchingVowels($strA); ...

Complex Notepad++ duplication, substitution, and addition operations

I have a collection of random strings listed on individual lines in my Notepad++. 127.0.0.1 badwebsite.com dontgohere.com Is there a way to transform them into the following format using Notepad++? {"blocked":true,"flagged":true,"string":"127.0.0.1","ja ...

Updating or deleting text from href with jquery / javascript

I am currently attempting to utilize the replace() method in order to eliminate specific strings from hyperlinks on my HTML pages. I have found several tutorials that demonstrate how to accomplish this using replace(), which seems to work well in IE. Howev ...

The complete text containing special characters needs to be replaced in a JSON format. What could be the issue?

I have some experience with fulltext and find / replace searches in MySQL, but I am facing a challenge with my latest attempt. The issue seems simple: I have a standard table and I want to find and replace a portion of JSON data with another. However, desp ...

Unexpected outcome when applying rtrim to DOCUMENT_ROOT

Is there a way to eliminate any trailing slashes from the DOCUMENT_ROOT? rtrim($_SERVER['DOCUMENT_ROOT'], '/\\') Unfortunately, after using rtrim, it is adding %5C: E:%5Cwamp%5Cwww%5Ctestfolder I even tried replacing all s ...