regex

Javascript Regex to match value of JSON key value pair

蹲街弑〆低调 提交于 2021-01-21 08:49:12
问题 Given the following key value pairs, how could I match just the values (including the quotes)? Explanation : I'm doing a find and replace in my IDE. I have hundreds of key/value pairs where the values need to be changed from strings to objects. So basically replacing the value. "ElevationFilenameIn": "Input raster elevation file", "TargetCRS": "Target vertical coordinate reference system Type", "featureName": "The name of the feature to extract, for example \"Vegetation\" or \"Water\"",

Regex 首字母转大写/小写,全大写,全小写

烈酒焚心 提交于 2021-01-21 08:02:25
语法 \l 第一个字符小写,比【\L】或【\U】优先级别低,连续使用,第一个【\l】或【\u】优先 \L 后面所有字符小写,比【\l】或【\u】优先级别高 \u 第一个字符大写,比【\L】或【\U】优先级别低,连续使用,第一个【\l】或【\u】优先 \U 后面所有字符大写,比【\l】或【\u】优先级别高 英文转大写 BeginDate date 开始日期 搜索正则:([a -zA-Z]+)([\sa-zA-Z]+ ) 替换正则:\U$ 1 \e\l$ 2 结果:BEGINDATE DATE 开始日期 英文转小写 BeginDate date 开始日期 搜索正则:([a -zA-Z]+)([\sa-zA-Z]+ ) 替换正则:\L$ 1 \u$ 2 结果:begindate date 开始日期 首字母大写 beginDate date 开始日期 搜索正则:([a -zA-Z]+)([\sa-zA-Z]+ ) 替换正则:\u$ 1 \u$ 2 结果:BeginDate date 开始日期 首字母小写 BeginDate date 开始日期 搜索正则:([a -zA-Z]+)([\sa-zA-Z]+ ) 替换正则:\l$ 1 \u$ 2 结果:beginDate date 开始日期 来源: oschina 链接: https://my.oschina.net/u/4302374/blog

Why is an underscore (_) not regarded as a non-word character?

大憨熊 提交于 2021-01-21 07:23:32
问题 Why is an underscore (_) not regarded as a non-word character? This regexp \W matches all non-word character but not the underscore. 回答1: Referring to Jeffrey Friedl's book about Regular Expressions, this was a change in Perl Regular Expressions, originally. Back to 1988 according to characters that were allowed to name a Perl variable [Page 89]: Perl 2 was released in June 1988. Larry had replaced the regex code entirely, this time using a greatly enhanced version of the Henry Spencer

Why is an underscore (_) not regarded as a non-word character?

两盒软妹~` 提交于 2021-01-21 07:22:15
问题 Why is an underscore (_) not regarded as a non-word character? This regexp \W matches all non-word character but not the underscore. 回答1: Referring to Jeffrey Friedl's book about Regular Expressions, this was a change in Perl Regular Expressions, originally. Back to 1988 according to characters that were allowed to name a Perl variable [Page 89]: Perl 2 was released in June 1988. Larry had replaced the regex code entirely, this time using a greatly enhanced version of the Henry Spencer

Replacing an integer (n) with a character repeated n times

不羁的心 提交于 2021-01-21 04:25:30
问题 Let's say I have a string: "__3_" ...which I would like to turn into: "__###_" basically replacing an integer with repeated occurrences of # equivalent to the integer value. How can I achieve this? I understand that backreferences can be used with str.replace() var str = '__3_' str.replace(/[0-9]/g, 'x$1x')) > '__x3x_' And that we can use str.repeat(n) to repeat string sequences n times. But how can I use the backreference from .replace() as the argument of .repeat() ? For example, this does

Dart how to add commas to a string number

天涯浪子 提交于 2021-01-21 00:35:13
问题 I'm trying to adapt this: Insert commas into number string to work in dart, but no luck. either one of these don't work: print("1000200".replaceAllMapped(new RegExp(r'/(\d)(?=(\d{3})+$)'), (match m) => "${m},")); print("1000300".replaceAll(new RegExp(r'/\d{1,3}(?=(\d{3})+(?!\d))/g'), (match m) => "$m,")); Is there a simpler/working way to add commas to a string number? 回答1: You just forgot get first digits into group. Use this short one: '12345kWh'.replaceAllMapped(new RegExp(r'(\d{1,3})(?=(

Check if a string starts with http using Javascript

守給你的承諾、 提交于 2021-01-20 21:01:05
问题 I've been searching all over for an answer to this and all of the answers I've found haven't been in JavaScript. I need a way, in javascript, to check if a string starts with http, https, or ftp. If it doesn't start with one of those I need to prepend the string with http:// . indexOf won't work for me I don't think as I need either http, https or ftp. Also I don't want something like google.com/?q=http://google.com to trigger that as being valid as it doesn't start with an http whereas

Check if a string starts with http using Javascript

末鹿安然 提交于 2021-01-20 21:00:06
问题 I've been searching all over for an answer to this and all of the answers I've found haven't been in JavaScript. I need a way, in javascript, to check if a string starts with http, https, or ftp. If it doesn't start with one of those I need to prepend the string with http:// . indexOf won't work for me I don't think as I need either http, https or ftp. Also I don't want something like google.com/?q=http://google.com to trigger that as being valid as it doesn't start with an http whereas

Check if a string starts with http using Javascript

有些话、适合烂在心里 提交于 2021-01-20 20:59:47
问题 I've been searching all over for an answer to this and all of the answers I've found haven't been in JavaScript. I need a way, in javascript, to check if a string starts with http, https, or ftp. If it doesn't start with one of those I need to prepend the string with http:// . indexOf won't work for me I don't think as I need either http, https or ftp. Also I don't want something like google.com/?q=http://google.com to trigger that as being valid as it doesn't start with an http whereas

Extract digits from string - Google spreadsheet

冷暖自知 提交于 2021-01-20 15:56:11
问题 In Google spreadsheets, I need a formula to extract all digits (0 to 9) contained into an arbitrary string, that might contain any possible character and put them into a single cell. Examples (Input -> Output) d32Ελληνικάfe9j.r/3-fF66 -> 329366 h01j2j3jFxF$$4j5j6j7j8j9 -> 0123456789 回答1: You may replace all non-digit characters using the \D+ regex and an empty string replacement with =REGEXREPLACE(A11,"\D+", "") or with casting it to a number: =VALUE(REGEXREPLACE(A11,"\D+", "")) 回答2: These