replace

Use DomDocument to replace all header tags with the h4 tags

自古美人都是妖i 提交于 2019-12-30 12:04:42
问题 I've used DomDocument to to GetElementById. It has selected a div. I need to replace all the header tags within that div with the h4 tag. 回答1: You have not made clear in your question what the concrete problem is you run into. I would assume that there are two parts that could cause you some questions marks. The first one would be how to get the hand on all the elements that you want to rename and the second one is actually how to rename an element. Get Heading Elements of a DOMDocument So

Javascript regex replace text with emoticons

纵然是瞬间 提交于 2019-12-30 11:33:11
问题 I need to replace text like ;) or :p by emoticon but I can't create a regex in order to detect this. Now i can detect only like :wink: function replaceEmoticons(text) { var emots = { ";)": "wink", ":)": "xxx", ":p": "xxx", }; return text.replace(/:(.*?):/g, function (match) { return typeof emots[match] != 'undefined' ? '<img src="http://localhost:8080/'+emots[match]+'.png"/>' : match; }); } What is the good regex for that ? 回答1: Try the following.However, you should escape the special

Java regex to replace file path based on OS

一个人想着一个人 提交于 2019-12-30 10:57:29
问题 I'm not very sure there is any regex to replace thoese things: This is a string value read from a xml file saved through Linux machine <pcs:message schema="models/HL7_2.5.model"/> and this is the one saved in Windows machine <pcs:message schema="model\HL7_2.5.model"/> This is why the file getting an error in eclipse while exported in Linux and imported in Windows or vise versa. Is there any regex to find and replace the value(slash and back slash) within String? (not XML parsing) based on

Replacing specific characters in first column of text

只愿长相守 提交于 2019-12-30 09:43:26
问题 I have a text file and I'm trying to replace a specific character (.) in the first column to another character (-). Every field is delimited by comma. Some of the lines have the last 3 columns empty, so they have 3 commas at the end. Example of text file: abc.def.ghi,123.4561.789,ABC,DEF,GHI abc.def.ghq,124.4562.789,ABC,DEF,GHI abc.def.ghw,125.4563.789,ABC,DEF,GHI abc.def.ghe,126.4564.789,,, abc.def.ghr,127.4565.789,,, What I tried was using awk to replace '.' in the first column with '-',

Replacing specific characters in first column of text

我的梦境 提交于 2019-12-30 09:43:21
问题 I have a text file and I'm trying to replace a specific character (.) in the first column to another character (-). Every field is delimited by comma. Some of the lines have the last 3 columns empty, so they have 3 commas at the end. Example of text file: abc.def.ghi,123.4561.789,ABC,DEF,GHI abc.def.ghq,124.4562.789,ABC,DEF,GHI abc.def.ghw,125.4563.789,ABC,DEF,GHI abc.def.ghe,126.4564.789,,, abc.def.ghr,127.4565.789,,, What I tried was using awk to replace '.' in the first column with '-',

PHP中的正则

﹥>﹥吖頭↗ 提交于 2019-12-30 09:09:10
概述 正则表达式是一种描述字符串结果的语法规则,是一个特定的格式化模式,可以匹配、替换、截取匹配的字符串。 j简单的说就是 通过一些规定的符号和字符组合成的一种语法规则 其实,只有了解一种语言的正则使用,其他语言的正则使用起来,就相对简单些。文本主要围绕解决下面问题展开。 有哪些常用的转义字符 什么是限定符与定位符 什么是单词定位符 特殊字符有哪些 什么是逆向引用以及怎样使用逆向引用 匹配模式 php中怎样使用正则表达式 php中哪些方面需要用到正则 怎样进行邮箱匹配,url匹配,手机匹配 怎样使用正则替换字符串中某些字符 贪婪匹配与惰性匹配区别 正则表达式之回溯与固态分组 正则优缺点有哪些 正则表达式的基本知识汇总 行定位符(^与$) 行定位符是用来描述字符串的边界。 “$” 表示行结尾 “^” 表示行开始如 "^de" ,表示以de开头的字符串 "de$" ,表示以de结尾的字符串。 单词定界符 我们在查找的一个单词的时候,如an是否在一个字符串”gril and body”中存在,很明显如果匹配的话,an肯定是可以匹配字符串“gril and body”匹配到,怎样才能让其匹配单词,而不是单词的一部分呢?这时候,我们可以是哟个单词定界符\b。 \ban\b 去匹配”gril and body”的话,就会提示匹配不到。 当然还有一个大写的\B,它的意思,和\b正好相反

How to replace every other instance of a particular character in a MySQL string?

倖福魔咒の 提交于 2019-12-30 07:56:46
问题 How to replace value in mysql column by query like, Column is options and its of type varchar(255) From id options 1 A|10|B|20|C|30 2 A|Positive|B|Negative To id options 1 A|10,B|20,C|30 2 A|Positive,B|Negative I am doing it by php like this. <?php $str = "A|10|B|20|C|30"; $arr = explode("|",$str); $newArr = array(); for($i=0;$i<count($arr);$i+=2){ if($arr[$i] && $arr[$i+1]){ $newArr[] = $arr[$i]."|".$arr[$i+1]; } } echo "Before:".$str."\n"; echo "After :".implode(",",$newArr); ?> https:/

Prevent double space when entering username

半世苍凉 提交于 2019-12-30 07:33:50
问题 When users register to my website I want to allow them to use spaces in their username, but only one space per word. My current code: $usor = $_POST['usernameone']; $allowed = "/[^a-z0-9 ]/i"; $username = preg_replace($allowed,"",$usor); $firstlettercheck = $username[0]; $lastlettercheck = substr("$username", -1); if ($firstlettercheck == " " or $lastlettercheck == " ") { echo "Usernames can not contain a space at start/end of username."; } What do I need to add to ensure there is only one

mysql: How can I remove character at start or end of field

别来无恙 提交于 2019-12-30 05:39:07
问题 I have field that contains a comma-separated list. Some old records have a comma at the beginning or end of the field. I need to remove these extra commas. Example: ,the,their,then to the,their,then or the,their,then, to the,their,then EDIT: I am looking for an UPDATE statement. I need to change the records. 回答1: Check this website SELECT TRIM(TRAILING 'xyz' FROM 'barxxyz'); which in your case would be ',' instead of 'xyz' 回答2: @codingbiz, Thank you for the website link: Quick examples:

2019-12-29(134)

别说谁变了你拦得住时间么 提交于 2019-12-30 04:46:58
191、生成一个变量名文件:文件内容在100行到999行之间,每行内容是一个变量,满足变量定义规则,字母或下划线开头,不能以数字开头,可以包含字母、数字、下划线 import random import string file_line_count=random.randint(100,999) print("文件行数为:",file_line_count) with open("d:\\2019\\1.txt","w") as fp: for i in range(file_line_count): #行数循环 first_letter=random.choice(string.ascii_letters+"_") other_letter="" for j in range(5): other_letter+=random.choice(string.ascii_letters+string.digits+"_") content=first_letter+other_letter fp.write(content+"\n") file_line_count=random.randint(100,999) print("文件行数为:",file_line_count) with open("d:\\2019\\1.txt","a") as fp: for i in range