regex

Regular expression negative match

岁酱吖の 提交于 2021-01-27 02:27:47
问题 I can't seem to figure out how to compose a regular expression (used in Javascript) that does the following: Match all strings where the characters after the 4th character do not contain "GP". Some example strings: EDAR - match! EDARGP - no match EDARDTGPRI - no match ECMRNL - match I'd love some help here... 回答1: Use zero-width assertions: if (subject.match(/^.{4}(?!.*GP)/)) { // Successful match } Explanation: " ^ # Assert position at the beginning of the string . # Match any single

URL regex in django with limited set of words

余生颓废 提交于 2021-01-27 02:12:05
问题 Given the following django URL conf. entry: url(r'^(?P<obj_ctype_name>\w+)/(?P<obj_id>\d+)/$', views.obj_view, name='obj_view') How would I rewrite the parameter (?P<obj_ctype_name>\w+) to enforce that it may only be one of "foo" "bar" or "baz" and still keep it as a named parameter? 回答1: (?P<obj_ctype_name>foo|bar|baz) 来源: https://stackoverflow.com/questions/1996305/url-regex-in-django-with-limited-set-of-words

URL regex in django with limited set of words

折月煮酒 提交于 2021-01-27 02:08:57
问题 Given the following django URL conf. entry: url(r'^(?P<obj_ctype_name>\w+)/(?P<obj_id>\d+)/$', views.obj_view, name='obj_view') How would I rewrite the parameter (?P<obj_ctype_name>\w+) to enforce that it may only be one of "foo" "bar" or "baz" and still keep it as a named parameter? 回答1: (?P<obj_ctype_name>foo|bar|baz) 来源: https://stackoverflow.com/questions/1996305/url-regex-in-django-with-limited-set-of-words

How to split a string by uppercase and lowercase in JavaScript?

ぃ、小莉子 提交于 2021-01-26 20:36:00
问题 Is it possible to split Strings in JavaScript by case such that the following string below (myString) would be converted into the array (myArray) below: var myString = "HOWtoDOthis"; var myArray = ["HOW", "to", "DO", "this"]; I have tried the regex below, but it only splits for camelCase: .match(/[A-Z]*[^A-Z]+/g); 回答1: ([A-Z]+|[a-z]+) . Match all upper case, or all lower case multiple times in capturing groups. Give this a try here: https://regex101.com/r/bC8gO3/1 回答2: Another way to do this

Please help, my regular expression is not consistently producing the right group matches [duplicate]

孤者浪人 提交于 2021-01-26 02:08:15
问题 This question already has answers here : Is there a way to apply regex modifiers for HTML5 input's pattern-attribute? (1 answer) Passing regex modifier options to RegExp object (6 answers) Closed 6 days ago . Update : There were actually three problems, the first reply comment and answer fixes problem one , where the regular expression match/exec methods return NULL . However, after I updated my code in this question, I am not getting all of the matches that the online regular expression

Test column for special characters or only characters / numbers

♀尐吖头ヾ 提交于 2021-01-24 14:10:31
问题 I tried finding special characters using generic regex attributes and NOT LIKE clause but have been getting confusing results. The research suggested that it does not work the way it works in SQL Server or elsewhere. For finding if there is any character For finding if there is any number For finding if there is any special character like '%[^0-9]%' or '%[^a-Z]%' does not work very well when finding if non-numeric data is available and if non-alphabetical data is present, respectively SELECT

Test column for special characters or only characters / numbers

走远了吗. 提交于 2021-01-24 14:09:10
问题 I tried finding special characters using generic regex attributes and NOT LIKE clause but have been getting confusing results. The research suggested that it does not work the way it works in SQL Server or elsewhere. For finding if there is any character For finding if there is any number For finding if there is any special character like '%[^0-9]%' or '%[^a-Z]%' does not work very well when finding if non-numeric data is available and if non-alphabetical data is present, respectively SELECT

Test column for special characters or only characters / numbers

假如想象 提交于 2021-01-24 14:01:29
问题 I tried finding special characters using generic regex attributes and NOT LIKE clause but have been getting confusing results. The research suggested that it does not work the way it works in SQL Server or elsewhere. For finding if there is any character For finding if there is any number For finding if there is any special character like '%[^0-9]%' or '%[^a-Z]%' does not work very well when finding if non-numeric data is available and if non-alphabetical data is present, respectively SELECT

javascript中的正则表达式(一)

三世轮回 提交于 2021-01-24 10:43:13
关于JavaScript中的正则表达式 什么是正则表达式 1.创建第一个正则表达式 2.使用字面量创建正则表达式 3.知识点和例子 4.[^ ]除了 5. 量词 什么是正则表达式 正则表达式,又称规则表达式。(英语:Regular Expression,在代码中常简写为regex、regexp或RE),计算机科学的一个概念。正则表达式通常被用来检索、替换那些符合某个模式(规则)的文本。 1.创建第一个正则表达式 var reg = new RegExp ( "a" , "i" ) ; ` console . log ( reg . test ( "abc" ) ) ; var 变量名 = new RegExp ( "正则表达式" , "匹配模式" ) ; //test()这个方法是检查一个字符串是否符合正则表达式的规则,如果符合会返回true反之false. 匹配模式分两种:i 忽略大小写 g 全局匹配模式 2.使用字面量创建正则表达式 语法: var 变量= /正则表达式/匹配模式 var var reg = /a/i ; eg:创建一个正则表达式,检查一个字符串中是否有a或者b var reg = /a|b|c/ ; console . log ( reg . test ( "bacd" ) ) ; 控制台会返回true?false? 可以自己试验一下。 3.知识点和例子 //

Why does LF and CRLF behave differently with /^\s*$/gm regex?

廉价感情. 提交于 2021-01-24 09:45:08
问题 I've been seeing this issue on Windows. When I try to clear any whitespace on each line on Unix: const input = `=== HELLO WOLRD ===` console.log(input.replace(/^\s+$/gm, '')) This produces what I expect: === HELLO WOLRD === i.e. if there were spaces on blank lines, they'd get removed. On the other hand, on Windows, the regex clears the WHOLE string. To illustrate: const input = `=== HELLO WOLRD ===`.replace(/\r?\n/g, '\r\n') console.log(input.replace(/^\s+$/gm, '')) (template literals will