regex

JavaScript: `new RegExp('hi')` versus `RegExp('hi')`? [duplicate]

旧城冷巷雨未停 提交于 2021-02-08 02:13:35
问题 This question already has answers here : JavaScript: using constructor without operator 'new' (2 answers) Closed 4 years ago . What is the difference between RegExp('hi') and new RegExp('hi') ? Does the new keyword do anything here? 回答1: It is identical The RegExp constructor is the %RegExp% intrinsic object and the initial value of the RegExp property of the global object. When RegExp is called as a function rather than as a constructor, it creates and initializes a new RegExp object. Thus

JavaScript: `new RegExp('hi')` versus `RegExp('hi')`? [duplicate]

℡╲_俬逩灬. 提交于 2021-02-08 02:13:30
问题 This question already has answers here : JavaScript: using constructor without operator 'new' (2 answers) Closed 4 years ago . What is the difference between RegExp('hi') and new RegExp('hi') ? Does the new keyword do anything here? 回答1: It is identical The RegExp constructor is the %RegExp% intrinsic object and the initial value of the RegExp property of the global object. When RegExp is called as a function rather than as a constructor, it creates and initializes a new RegExp object. Thus

Regex includes two matches in first match

a 夏天 提交于 2021-02-07 23:52:51
问题 I have this regex that tries to find individual STEP-lines and divides it into three goups of reference number, class and properties: #14=IFCEXTRUDEDAREASOLID(#28326,#17,#9,3657.6); becomes [['14'], ['IFCEXTRUDEDAREASOLID'], ['#28326,#17,#9,3657.6']] Sometimes these lines have arbitrary line breaks, especially among the properties, so I put some \s in the regex. This however makes for an interesting bug. The pattern now matches TWO rows into every match. How can I adjust the regex to only

Why is this regular expression failing to match the second 6 digit number?

喜欢而已 提交于 2021-02-07 23:46:41
问题 I can't understand why the following PowerShell is not working: ([regex]"(^|\D)(\d{6})(\D|$)").Matches( "123456 123457" ).Value The code above code produces: 123456 Why is it not matching both numbers? 回答1: The "(^|\D)(\d{6})(\D|$)" regex matches and consumes a non-digit char before and after 6 digits (that is, the space after 123456 is consumed during the first iteration). Use a non-consuming construct, lookbehind and lookahead: "(?<!\d)\d{6}(?!\d)" See a .NET regex demo. The (?<!\d)

Why is this regular expression failing to match the second 6 digit number?

走远了吗. 提交于 2021-02-07 23:44:15
问题 I can't understand why the following PowerShell is not working: ([regex]"(^|\D)(\d{6})(\D|$)").Matches( "123456 123457" ).Value The code above code produces: 123456 Why is it not matching both numbers? 回答1: The "(^|\D)(\d{6})(\D|$)" regex matches and consumes a non-digit char before and after 6 digits (that is, the space after 123456 is consumed during the first iteration). Use a non-consuming construct, lookbehind and lookahead: "(?<!\d)\d{6}(?!\d)" See a .NET regex demo. The (?<!\d)

Determine if two names are close to each other

六眼飞鱼酱① 提交于 2021-02-07 23:13:19
问题 I'm making a system for my school where we can check if a student is black-listed, at parties and other events. It's easy for me to check if a student is black-listed, since I can just look the student up in my database and see if he/she is black-listed. Here is where it gets difficult though. At our parties, each student can invite one person. In theory a student who is black-listed, can be invited by another student and bypass the system. I cannot check the guest table for students black

VI delete everything except a pattern

不打扰是莪最后的温柔 提交于 2021-02-07 22:32:30
问题 I have a huge JSON output and I just need to delete everything except a small string in each line. The string has the format "title": "someServerName" the "someServerName" (the section within quotes) can vary wildly. The closest I've come is this: :%s/\("title":\s"*"\) But this just manages to delete "title": " The only thing I want left in each line is "title": "someServerName" EDIT to answer the posted question: The Text I'm going to be working with will have a format similar to {"_links":

VI delete everything except a pattern

我怕爱的太早我们不能终老 提交于 2021-02-07 22:31:05
问题 I have a huge JSON output and I just need to delete everything except a small string in each line. The string has the format "title": "someServerName" the "someServerName" (the section within quotes) can vary wildly. The closest I've come is this: :%s/\("title":\s"*"\) But this just manages to delete "title": " The only thing I want left in each line is "title": "someServerName" EDIT to answer the posted question: The Text I'm going to be working with will have a format similar to {"_links":

How to ignore white space with regex?

时光怂恿深爱的人放手 提交于 2021-02-07 21:11:11
问题 Here is my regex: ^(SK{1}[0-9]{8})$ But I want text like this: SK 283 92758 SK 283 92 7 58 to be taken as this: SK28392758 It is possible? 回答1: Use the "optional" quantifier ? for a space between each character: ^S ?K ?(\d ?){7}\d$ This allows an optional space between the characters. To allow any number of spaces, replace every ? with * . See live demo. I also removed unnecessary brackets: {1} is pointless the brackets around the whole thing are unecessary; group 0 , which is the whole match

How to ignore white space with regex?

一笑奈何 提交于 2021-02-07 21:05:05
问题 Here is my regex: ^(SK{1}[0-9]{8})$ But I want text like this: SK 283 92758 SK 283 92 7 58 to be taken as this: SK28392758 It is possible? 回答1: Use the "optional" quantifier ? for a space between each character: ^S ?K ?(\d ?){7}\d$ This allows an optional space between the characters. To allow any number of spaces, replace every ? with * . See live demo. I also removed unnecessary brackets: {1} is pointless the brackets around the whole thing are unecessary; group 0 , which is the whole match