regex

Why do I have to pass a callable to re.sub to make an uppercase string?

非 Y 不嫁゛ 提交于 2021-02-19 03:34:46
问题 Below is a somewhat contrived example that get's at my eventual question... I would like to use regex to uppercase the first character of a possessive noun. Let's say that I have a regular expression that (probably poorly) matches possessive nouns. ie... ### Regex explanation ### # 1. match a word break # 2. match a word-like character and capture in a group # 3. lookahead for some more characters + the substring "'s" >>> my_re = re.compile(r"\b(\w)(?=\w+'s)") >>> re.search(my_re, "bruce's

Gorilla Mux Regex

☆樱花仙子☆ 提交于 2021-02-19 03:28:12
问题 I'm using the Mux package from the Golang Gorilla Toolkit for my routes. Consider the following routes: m.HandleFunc("/admin/install", installHandler).Methods("GET") m.HandleFunc("/admin/^((?!install).)*$", adminHandler).Methods("GET") m.HandleFunc("/admin", adminHandler).Methods("GET") The problem is with the regex of the middle route - it is not interpreted, so the route will not work! m.HandleFunc("/admin/{^((?!install).)*$}", adminHandler).Methods("GET") With the {} curly brackets doesn't

Regex - any alphabet except “e”

拜拜、爱过 提交于 2021-02-19 02:12:35
问题 I want to make a regular expression for any alphabets except "e" This is what I came up with - /([a-d]|[f-z])+?/i The above regex doesn't match "e" which is good. It matches for "amrica" But it also match "america" but it shouldn't because of the "e" in america What am I doing wrong? 回答1: You need the anchors ^ (beginning of the string) and $ (end of the string); otherwise your pattern can partially match any string as long as it contains an alphabet other than e : /^[a-df-z]+$/i.test(

Regex - any alphabet except “e”

倖福魔咒の 提交于 2021-02-19 02:09:39
问题 I want to make a regular expression for any alphabets except "e" This is what I came up with - /([a-d]|[f-z])+?/i The above regex doesn't match "e" which is good. It matches for "amrica" But it also match "america" but it shouldn't because of the "e" in america What am I doing wrong? 回答1: You need the anchors ^ (beginning of the string) and $ (end of the string); otherwise your pattern can partially match any string as long as it contains an alphabet other than e : /^[a-df-z]+$/i.test(

Regex - any alphabet except “e”

谁说胖子不能爱 提交于 2021-02-19 02:08:05
问题 I want to make a regular expression for any alphabets except "e" This is what I came up with - /([a-d]|[f-z])+?/i The above regex doesn't match "e" which is good. It matches for "amrica" But it also match "america" but it shouldn't because of the "e" in america What am I doing wrong? 回答1: You need the anchors ^ (beginning of the string) and $ (end of the string); otherwise your pattern can partially match any string as long as it contains an alphabet other than e : /^[a-df-z]+$/i.test(

How Do You Comment Out the */ Part of a Regular Expression in PHP

安稳与你 提交于 2021-02-19 01:57:19
问题 I have preg_replace function that I'm calling and putting on multiple lines for readability but the */ characters in the regex mess up the comments. How can I comment out all these lines without moving them all onto one line? return preg_replace('/.*/', 'Lorem Ipsum' . 'More Lorem Ipsum' , $foo); 回答1: You could use a different regex pattern delimiter character: return preg_replace('#.*#', 'Lorem Ipsum' . 'More Lorem Ipsum' , $foo); EDIT: The delimiter character is a feature of PCRE (Perl

pandas extractall() is not extracting all cases given a regex?

牧云@^-^@ 提交于 2021-02-19 01:21:22
问题 I have a nested list of strings which I would like to extract them the date. The date format is: Two numbers (from 01 to 12 ) hyphen tree letters (a valid month) hyphen two numbers, for example: 08-Jan—07 or 03-Oct—01 I tried to use the following regex: r'\d{2}(—|-)(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\d{2,4}' Then I tested it as follows: import pandas as pd df = pd.DataFrame({'blobs':['6-Feb- 1 4 Facebook’s virtual-reality division created a 3-EBÚ7 11 network of 500 free demo

pandas extractall() is not extracting all cases given a regex?

守給你的承諾、 提交于 2021-02-19 01:10:39
问题 I have a nested list of strings which I would like to extract them the date. The date format is: Two numbers (from 01 to 12 ) hyphen tree letters (a valid month) hyphen two numbers, for example: 08-Jan—07 or 03-Oct—01 I tried to use the following regex: r'\d{2}(—|-)(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\d{2,4}' Then I tested it as follows: import pandas as pd df = pd.DataFrame({'blobs':['6-Feb- 1 4 Facebook’s virtual-reality division created a 3-EBÚ7 11 network of 500 free demo

How do I match only fully-composed characters in a Unicode string in Perl?

怎甘沉沦 提交于 2021-02-18 22:10:27
问题 I'm looking for a way to match only fully composed characters in a Unicode string. Is [:print:] dependent upon locale in any regular expression implementation that incorporates this character class? For example, will it match Japanese character 'あ', since it is not a control character, or is [:print:] always going to be ASCII codes 0x20 to 0x7E? Is there any character class, including Perl REs, that can be used to match anything other than a control character? If [:print:] includes only

Regex to match strings that begin with specific word and after that words seperated by slashes

瘦欲@ 提交于 2021-02-18 18:38:40
问题 So i want to match all strings of the form with a regex (word1|word2|word3)/some/more/text/..unlimited parts.../more so it starts with specific word and it does not end with / examples to match: word1/ok/ready word2/hello word3/ok/ok/ok/ready What i want in the end is when i have a text with above 3 examples in it (spread around in a random text), that i receive an array with those 3 matches after doing regex.exec(text); Anybody an idea how to start? Thanks! 回答1: Something like this should