regex

Python regex - Replace bracketed text with contents of brackets

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-07 17:54:08
问题 I'm trying to write a Python function that replaces instances of text surrounded with curly braces with the contents of the braces, while leaving empty brace-pairs alone. For example: foo {} bar {baz} would become foo {} bar baz . The pattern that I've created to match this is {[^{}]+} , i.e. some text that doesn't contain curly braces (to prevent overlapping matches) surrounded by a set of curly braces. The obvious solution is to use re.sub with my pattern, and I've found that I can

How can i use php's preg_replace with a simple string and wildcards?

巧了我就是萌 提交于 2021-02-07 17:24:53
问题 If i have the string [link="*"] where * is a wildcard how could i then use php to replace the string with <a href="*"> where * is the same value as before? Is preg_replace the best way to do this? Thanks, any help appreciated! 回答1: preg_replace('~\[link="(.*?)"\]~', '<a href="$1">', $text); 回答2: $link = '[link="http://www.google.com/"]'; $link = preg_replace('/\[link="(.*)"\]/', '<a href="$1">', $link); 来源: https://stackoverflow.com/questions/7050152/how-can-i-use-phps-preg-replace-with-a

how to detect CTRL+C and CTRL+V key pressing using regular expression?

这一生的挚爱 提交于 2021-02-07 17:02:12
问题 I have blocked all aTOz character input for my text field using regular expression in my JavaScript but as I have blocked entire alphabets I am not able to perform CTRL + C and CTRL + V , here is my regular expression goes: var reValidChars = /[\x08\x0D\d]/; iKeyCode = objEvent.charCode; strKey = String.fromCharCode(iKeyCode); if (!reValidChars.test(strKey)) { return false; } Could you please help me in this issue. Thanks in advance 回答1: You can't detect key pressing with RegExp, though you

Regex to include one thing but exclude another

痞子三分冷 提交于 2021-02-07 14:55:09
问题 I've been having a lot of trouble finding how to write a regex to include certain URLs starting with a specified phrase while excluding another. We want to include pages that start with: /womens /mens /kids-clothing/boys /kids-clothing/girls /homeware But we want to exclude anything that has /sXXXXXXX in the URL - where the X's are numbers. I've written this so far to match the below URLs but it's behaving very oddly. Should I be using lookarounds or something? \/(womens|mens|kids\-clothing\

Regex to include one thing but exclude another

帅比萌擦擦* 提交于 2021-02-07 14:54:19
问题 I've been having a lot of trouble finding how to write a regex to include certain URLs starting with a specified phrase while excluding another. We want to include pages that start with: /womens /mens /kids-clothing/boys /kids-clothing/girls /homeware But we want to exclude anything that has /sXXXXXXX in the URL - where the X's are numbers. I've written this so far to match the below URLs but it's behaving very oddly. Should I be using lookarounds or something? \/(womens|mens|kids\-clothing\

C# RegEx to find a specific string or all words in a string

社会主义新天地 提交于 2021-02-07 14:43:06
问题 Looking it up, I thought I understood how to look up a string of multiple words in a sentence, but it does not find a match. Can someone tell me what I am doing wrong? I need to be able to find a single or multiple word match. I passed in "to find" to the method and it did not find the match. Also, if the user does not enclose their search phrase in quotes, I also need it to search on each word entered. var pattern = @"\b\" + searchString + @"\b"; //searchString is passed in. Regex rgx = new

C# RegEx to find a specific string or all words in a string

早过忘川 提交于 2021-02-07 14:42:39
问题 Looking it up, I thought I understood how to look up a string of multiple words in a sentence, but it does not find a match. Can someone tell me what I am doing wrong? I need to be able to find a single or multiple word match. I passed in "to find" to the method and it did not find the match. Also, if the user does not enclose their search phrase in quotes, I also need it to search on each word entered. var pattern = @"\b\" + searchString + @"\b"; //searchString is passed in. Regex rgx = new

C# RegEx to find a specific string or all words in a string

走远了吗. 提交于 2021-02-07 14:41:08
问题 Looking it up, I thought I understood how to look up a string of multiple words in a sentence, but it does not find a match. Can someone tell me what I am doing wrong? I need to be able to find a single or multiple word match. I passed in "to find" to the method and it did not find the match. Also, if the user does not enclose their search phrase in quotes, I also need it to search on each word entered. var pattern = @"\b\" + searchString + @"\b"; //searchString is passed in. Regex rgx = new

How can I get “grep -zoP” to display every match separately?

拟墨画扇 提交于 2021-02-07 14:36:36
问题 I have a file on this form: X/this is the first match/blabla X-this is the second match- and here we have some fluff. And I want to extract everything that appears after "X" and between the same markers. So if I have "X+match+", I want to get "match", because it appears after "X" and between the marker "+". So for the given sample file I would like to have this output: this is the first match and then this is the second match I managed to get all the content between X followed by a marker by

How can I get “grep -zoP” to display every match separately?

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-07 14:35:20
问题 I have a file on this form: X/this is the first match/blabla X-this is the second match- and here we have some fluff. And I want to extract everything that appears after "X" and between the same markers. So if I have "X+match+", I want to get "match", because it appears after "X" and between the marker "+". So for the given sample file I would like to have this output: this is the first match and then this is the second match I managed to get all the content between X followed by a marker by