regex

need to get everything after 2nd dash in string?

痞子三分冷 提交于 2021-02-16 09:10:02
问题 I have string values like those below: string str1 = "123-456-test"; string str1 = "123 - 456 - test-test"; string str1 = "123-REQ456-test"; string str1 = "123 - REQ456 - test-test"; I need to grab the entire content from string right after the 2nd dash. I tried String.Split('-') , but it did not work. I think I need to use a regex, but I am not able to find a correct one. Please suggest. 回答1: (?:[^-\n]+-){2}(.*)$ You can try this.Grab the capture.See demo. https://regex101.com/r/tS1hW2/21

Regular expression to find function calls in a file with Python regular expression?

喜你入骨 提交于 2021-02-16 09:09:31
问题 I would like a regular expression, of which I will use with the Python re module, that will look for python function calls within a python file, but there will be caveats around the function calls that I'm looking for. The function calls will have a single, specific name. The function calls may be chained, but will only have one chained call that will always have the same name. The first function will always take a single string argument. The chained function, however, might take arbitrary

Extracting `<key>=<value>` pairs with regex, dot group (.+?) not cooperating with optional space (\s)

徘徊边缘 提交于 2021-02-16 09:01:53
问题 I have this string: metadata=1.2 name=stone:supershare UUID=eff4e7bc:47aea5cf:0f0560f0:2de38475 I wish to extract from it the key and value pairs: <key>=<value> . /(\w+)=(.+?)\s/g This, as expected, doesn't return the UUID pair, due to not being followed by space: [ "metadata=1.2 ", "name=stone:supershare " ], [ "metadata", "name" ], [ "1.2", "stone:supershare" ] Now, obviously, we should make the \s lookup optional: /(\w+)=(.+?)\s?/g Though, this goes utterly nuts extracting only the first

Extracting `<key>=<value>` pairs with regex, dot group (.+?) not cooperating with optional space (\s)

Deadly 提交于 2021-02-16 08:59:34
问题 I have this string: metadata=1.2 name=stone:supershare UUID=eff4e7bc:47aea5cf:0f0560f0:2de38475 I wish to extract from it the key and value pairs: <key>=<value> . /(\w+)=(.+?)\s/g This, as expected, doesn't return the UUID pair, due to not being followed by space: [ "metadata=1.2 ", "name=stone:supershare " ], [ "metadata", "name" ], [ "1.2", "stone:supershare" ] Now, obviously, we should make the \s lookup optional: /(\w+)=(.+?)\s?/g Though, this goes utterly nuts extracting only the first

Regex to match everything except a list of characters

我与影子孤独终老i 提交于 2021-02-16 08:59:09
问题 I want to match a line containing everything except the specified characters [I|V|X|M|C|D|L] . new Regex(@"^(.*) is (?![I|V|X|M|C|D|L].*)$") should match everything except the characters mentioned in the OR list. Should match - name is a Should not match - edition is I 回答1: Try this pattern: ^[^IVXMCDL]*$ This will match the start of the string, followed by zero or more characters other than those specified in the character class, followed by the end of the string. In other words, it will not

Extracting `<key>=<value>` pairs with regex, dot group (.+?) not cooperating with optional space (\s)

流过昼夜 提交于 2021-02-16 08:59:08
问题 I have this string: metadata=1.2 name=stone:supershare UUID=eff4e7bc:47aea5cf:0f0560f0:2de38475 I wish to extract from it the key and value pairs: <key>=<value> . /(\w+)=(.+?)\s/g This, as expected, doesn't return the UUID pair, due to not being followed by space: [ "metadata=1.2 ", "name=stone:supershare " ], [ "metadata", "name" ], [ "1.2", "stone:supershare" ] Now, obviously, we should make the \s lookup optional: /(\w+)=(.+?)\s?/g Though, this goes utterly nuts extracting only the first

Replace username part in email addresses into asterisks

三世轮回 提交于 2021-02-16 08:52:52
问题 How can I convert username in email addresses into asterisks. The first and last letter in the username stay as it is and rest replaced with (*). Example: mhyunf@gmail.com into m****f@gmail.com 回答1: You can do it using look arounds. /(?!^).(?=[^@]+@)/ (?!^) Negative look behind. Checks if the character is not preceded by start of string. This ensures that the first character is not selected. . Matches a single character. (?=[^@]+@) Positive look ahead. Ensures that the single character

Is there a regular expression which matches a single grapheme cluster?

纵饮孤独 提交于 2021-02-16 06:37:46
问题 Graphemes are the user-perceived characters of a text, which in unicode may comprise of several codepoints. From Unicode® Standard Annex #29: It is important to recognize that what the user thinks of as a “character”—a basic unit of a writing system for a language—may not be just a single Unicode code point. Instead, that basic unit may be made up of multiple Unicode code points. To avoid ambiguity with the computer use of the term character, this is called a user-perceived character. For

Unbalanced parenthesis error with Regex

六眼飞鱼酱① 提交于 2021-02-16 05:32:53
问题 I am using the following regex to obtain all data from a website Javascript data source that is contained within the following character pattern [[]]); The code I am using is this: regex = r'\[\[.*?\]]);' match2 = re.findall(regex, response.body, re.S) print match2 This is throwing up an error message of: raise error, v # invalid expression sre_constants.error: unbalanced parenthesis I think I am fairly safe in assuming that this is being caused by the closing bracket within my regex. How can

Unbalanced parenthesis error with Regex

主宰稳场 提交于 2021-02-16 05:32:24
问题 I am using the following regex to obtain all data from a website Javascript data source that is contained within the following character pattern [[]]); The code I am using is this: regex = r'\[\[.*?\]]);' match2 = re.findall(regex, response.body, re.S) print match2 This is throwing up an error message of: raise error, v # invalid expression sre_constants.error: unbalanced parenthesis I think I am fairly safe in assuming that this is being caused by the closing bracket within my regex. How can