All my data have carriage return in url field:
ex:
see the cursor position.
After I remove manually the carriage return (with keyboard !), everything works fine:
(see the cursor position)
I tried:
UPDATE links set url= replace(url,'\r\n','');
UPDATE links set url= replace(url,'\n','');
UPDATE links set url= trim(url);
NOT good: How do I get rid of these carriage returns ?
UPDATE `link` SET `url` = TRIM('\r\n' FROM `url`);
The function TRIM() will only remove spaces and not line breaks and other characters. As their documentation says, it has "Remove leading and trailing spaces" for TRIM(). But you can specify characters to remove.
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html
Although the one you tried should work, also try:
update links SET url= TRIM(TRAILING '\r\n')
Another option:
UPDATE links SET url= REPLACE(url, '\r', '');
Btw, the above could also be formed like this:
UPDATE links SET url= REPLACE(REPLACE(url, '\r', ''), '\n', '');
This would remove both \r\n and \n
Related
I have a question about a WordPress URL in Google Chrome 94.0.4606.81:
I was reading a WordPress article recently and noticed that there is an  (OBJ) symbol in the URL. The symbol is also in the webpage title.
Take Ownership and Select Owner
Question:
What is the purpose of the  (OBJ) symbol -- and how is it possible that it has been included in a URL?
It seems like you got this symbol in the title field of the article. You can remove it from there. If you don't see it select everything in the field with ctrl + a and write the title new.
Honestly, I don't know what nature is this copy/paste issue in WP, and the "Object Replacement Character"
To avoid appearing this character it's enough to use Ctrl+Shift+V shortcut while pasting into WP post title field, means: Paste Text Without Formatting.
If you want to be sure in protecting the post slug (means: post URL) you can use the snippet in your functions.php:
/**
* Remove the strange [OBJ] character in the post slug
* See: https://github.com/WordPress/gutenberg/issues/38637
*/
add_filter("wp_unique_post_slug", function($slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug) {
return preg_replace('/(%ef%bf%bc)|(efbfbc)|[^\w-]/', '', $slug);
}, 10, 6);
preg_replace function searches here for string "%ef%bf%bc" or "efbfbc" (UTF-8 - hex encoded OBJ character) OR any character that IS NOT base alphanumeric character or dash character – to delete.
Since you've mentioned it also made into the title: I use this to filter the title on save to remove these special characters.
function sbnc_filter_title($title) {
// Concatenate separate diacritics into one character if we can
if ( function_exists('normalizer_normalize') && strlen( normalizer_normalize( $title ) ) < strlen( $title ) ) {
$title = normalizer_normalize( $title );
}
// Replace no-break-space with regular space
$title = preg_replace( '/\x{00A0}/u', ' ', $title );
// Remove whitespaces from the ends
$title = trim($title);
// Remove any invisible and control characters
$title = preg_replace('/[^\x{0020}-\x{007e}\x{00a1}-\x{FFEF}]/u', '', $title);
return $title;
}
add_filter('title_save_pre', 'sbnc_filter_title');
Please note that you may need to extend set of allowed UTF range in the preg_replace call based on the languages you support. The range in the example should suit most languages actively used in the word, but if you may write article titles that include archaic scripts like Linear-B, gothic etc. you may need to extend the ranges.
If you copy-pasted it from somewhere, like I did, remember to paste as text using Ctrl + Shift + V to avoid this.
Also, it is the case that this [OBJ] only appears in Chromium-based browsers like Chrome, Edge etc, unlike in Firefox which I believe discards it by default.
I have a text equation like: 10x^2-8y^2-7k^4=0.
How can I find the ^ and replace it with <sup>2</sup> in the whole string using regex. The result should be like:
I tried str = str.replace(/\^\s/g, "<sup>$1</sup> ") but I’m not getting the expected result.
Any ideas that can help to solve my problem?
I think you're looking for something like
\^(\d+)
It matches the ^, captures the exponent and replace with
<sup>$1</sup>
See it here at regex101.
Edit:
To meet your new demands, check this fiddle. It handles the sub as well using replace with a function.
Your current pattern matches a caret followed by a space character (space, tab, new-line, etc.), but you want to match a caret followed by a single character or multiple characters wrapped in accolades, as your string is in TeX.
/\^(?:([\w\d])|\{([\w\d]{2,})\})/g
Now, using str = str.replace(/\^(?:([\w\d])|\{([\w\d]{2,})\})/g, "<sup>$1</sup>"); should do the job.
You can make a more generic function from this expression that can wrap characters prefixed by a specific character with a specific tag.
function wrapPrefixed(string, prefix, tagName) {
return string.replace(new RegExp("\\" + prefix + "(?:([\\w\\d])|\\{([\\w\\d]{2,})\\})"), "<" + tagname + ">$1</" + tagname + ">");
}
For instance, calling wrapPrefixed("1_2 + 4_{3+2}", "_", "sub"); results in 1<sub>2</sub> + 4<sub>3+2</sub>.
I have a simple loop to delete all words from the end of a text that start with a # and space.
AS3:
// messageText is usually taken from a users input field - therefore the newline is not present in the "messageText"
var messageText = "hello world #foo lorem ipsum #findme"
while (messageText.lastIndexOf(" ") == messageText.lastIndexOf(" #")){
messageText = messageText.slice(0,messageText.lastIndexOf(" "));
}
How to check if the position before the # is not a space but a newline?
I tried this but nothing gets found:
while (messageText.lastIndexOf(" ") == messageText.lastIndexOf("\n#")){
messageText = messageText.slice(0,messageText.lastIndexOf(" "));
}
\n is the newline character in the Unix file definition.
\r\n is the Windows version.
\r is the OSX version.
See also: this previous (dupe) post.
First thing is I'd manually try replacing "\n" with "\r\n" and then "\r" to see if there is some other newline in use. If so, then you just need a better search term that will match each version in one go.
A better solution might be to use Regular Expression (RegExp). You are explicitly looking for the newline character and a space after it. You could use this regex pattern to look for the start of a line with a single space:
var pattern:RegExp = /^\s/;
if (yourString.search(pattern) >= 0) { ... }
The ^ carat character enforces that it's the start of a line. The \s is a placeholder for any whitespace character, so if you don't want to match tabs then change it to a blank space. (I'm not familiar with ActionScript specifically, but that syntax looks OK and search() will return -1 if the pattern isn't found).
I have a column which contains data like
thumb/RANDOM_STRING.JPG
thumb/cat/RANDOM_STRING.JPG
thumb/test/again/RANDOM_STRING.JPG
I want to contain only the Image name. And want to DELETE every word before / character.
Here is what I have tried but it does not work
UPDATE wsr_jshopping_products
SET product_full_image =
REPLACE(product_full_image,'thumb//', '');
if you just want the filename to remain use:
UPDATE wsr_jshopping_products
SET product_full_image = REVERSE(
SUBSTRING(
REVERSE(product_full_image),1,
LOCATE('/',REVERSE(product_full_image))-1))
I need to replace the special characters å,ä,ö (with a or o) within a MySQL database. How can I apply this search and replace only to affect image links? The images have either jpeg or jpg extension.
update your column with the desired data. Use a sequence of replaces, or write a custom function:
UPDATE mytable
SET link=REPLACE(link, 'ä,', 'a');
If your links are scattered in text, you can use substring_index to break it apart from the text using www. as the first delimiter, .jpg as the second, and re-concatenate with the rest of the text after replacing
set #a='sömetext www.göögle.com.jpg sömetext';
select concat(
substring_index(#a, 'www.', 1),
'www.',
replace(substring_index(substring_index(#a, '.jpg', 1), 'www.', -1), 'ö','o'),
'.jpg',
substring_index(#a, '.jpg', -1)
);
>sömetext www.google.com.jpg sömetext
Solved -
UPDATE wp_postmeta SET meta_value = REPLACE(REPLACE(REPLACE(meta_value, 'å', 'a') , 'ä', 'a') , 'ö', 'o')
WHERE LOWER(RIGHT(meta_value, 5)) = '.jpeg'
OR LOWER(RIGHT(meta_value, 4)) IN ('.jpg', '.gif', '.png')
You might want to squeeze in an additional parameter to look for and replace capital letters.