regex

Regular expression of different format of dates in python [duplicate]

不打扰是莪最后的温柔 提交于 2021-01-28 09:00:34
问题 This question already has answers here : Check if string has date, any format (2 answers) Closed 3 years ago . I am trying to write a regular expression to catch different format of dates. The sentences are in a series and each sample of the series contains only one date, but may have other numbers. The format of dates is like this: 04/20/2009; 04/20/09; 4/20/09; 4/3/09 Mar-20-2009; Mar 20, 2009; March 20, 2009; Mar. 20, 2009; Mar 20 2009; 20 Mar 2009; 20 March 2009; 20 Mar. 2009; 20 March,

How to remove parentheses and all data within using Python3

自古美人都是妖i 提交于 2021-01-28 08:54:36
问题 I'm trying to remove parenthesis and all data within using Python 3. I've looked into several different threads, including here: How to remove parentheses and all data within using Pandas/Python? After finally getting: re.sub(r"\(.*\)|\s-\s.*", r"", str1) to run without errors, it didn't remove the content from the str1 string. Then I tried this approach: How to remove text within parentheses from Python string? to remove the parenthesis and contents from the file before reading it in and

Regex that match 3 consecutive words that start and end with the same letter

只愿长相守 提交于 2021-01-28 08:50:13
问题 I have to match 3 consecutive words that start and end with same letters I have a code like this: import re def regex(file): with open(file) as f: s=f.read() rx=re.compile(r"([a-z])+\s+\1",re.I) r=re.findall(rx,s) print(r) return len(r) The text from the file is something like this dcvs xa Allo ozo zn bnro ce erdda anfgato e csdfa and i'm expecting this result: dcvs x a A ll o o zo zn bnro c e e rdd a a nfgato e csdfa [('a','o'),('e','a')] 2 but i'm getting this: ['a', 'o', 'e', 'a'] 4 Any

PHP preg match *.domain.com or *.domain.co.uk

孤者浪人 提交于 2021-01-28 08:45:58
问题 I'm using this code to preg match for *.domain.com but need it changed to also include foreign domains which have a few periods like *.domain.co.uk. Any helps appreciated thanks if (trim(preg_match('!^https?://([^/]+\.)?domain\.com(/|#|$)!i', $documentLink->getAttribute('href')))) Just an update that i'm looking to match *.domain.(any TLD) not just co.uk Thanks 回答1: !^https?://([^/]+\.)?domain(.com|co.uk)(/|#|$)!i 回答2: !^https?://([^/]+\.)?domain[.a-z]+(/|#|$)!i 回答3: !^(https?://)?([\w-]+\.)

mongodb regex doesn't work

六眼飞鱼酱① 提交于 2021-01-28 08:36:27
问题 I'm aware, there are many similar questions related to mongodb regex, including: MongoDB Regex Query : Why doesn't this work? and MongoDB regex matching trouble In the first question, it was said that try.mongodb.com has a bug that make regex doesn't work. In the second question, and many other question, the problem was related to wrong regex format. I have see the questions, and seemingly my problem is a bit different (or I might miss something here). What I have try In short, this one works

Lookahead regex failing to find the same overlapping matches

佐手、 提交于 2021-01-28 08:20:52
问题 Is it possible to find overlapping matches using regular expressions when searching again for the same pattern? I want to be able to find matches that occurs three times. For example babab occurs three times in babababab : babab abab ba babab ab baba babab This is my current Python implementation: import re matches = re.findall(r'(?=(\w+).*\1).*\1', "babababab") print(matches) My program find only baba instead of babab . Thanks! 回答1: We can generalize the solution to any regex. Let's say we

Singapore Mobile Number RegEx [closed]

巧了我就是萌 提交于 2021-01-28 08:15:00
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 years ago . Improve this question The Phone Number Should Start with +65, Followed By 6|8|9 with Total of 11 Digits For Ex : +6598798765 Thank You 回答1: /\+65(6|8|9)\d{7}/g \+ matches the character + literally (case sensitive) 65 matches the characters 65 literally (case sensitive) 1st Capturing Group (6|8|9)

Java regular expression to get characters between double quotes

主宰稳场 提交于 2021-01-28 08:11:32
问题 I need to figure out a regular expression (Pattern) to be able to get characters between double quotes. It's a little hard to explain, but here is what I want: If I run this through said expression: say("ex" + "ex2", "ex3"); I will then be able to get three matches, which are; "ex", "ex2", and "ex3" all in their own strings. I've already tried this expression: Pattern.compile("\\\"(.*)\\\""); But instead of giving me three different .group() s, I get one .group which is "ex", "ex2", and "ex3"

Python: How to use re.search() in a compound if statement (is it even possible?)

亡梦爱人 提交于 2021-01-28 07:53:07
问题 I need to see if a line contains 2 numbers, and if the first one is less than 0.5: if re.search('((?:\d|[.\-\+]\d|[\+\-]\.\d)[\d\.\-\+e]*)[^\d\.\-\+]+((?:\d|[.\-\+]\d|[\-\+]\.\d)[\d\.\-\+e]*)',foil[ifrom],re.IGNORECASE) and float(re.group(1))<0.5: #above is wrong: no such thing as re.group(1)... elif re.search('((?:\d|[.\-\+]\d|[\+\-]\.\d)[\d\.\-\+e]*)[^\d\.\-\+]+((?:\d|[.\-\+]\d|[\-\+]\.\d)[\d\.\-\+e]*)',foil[midsep+1],re.IGNORECASE) and float(re.group(1))>0.5: #also wrong What would be the

Python regex: Bad character range

二次信任 提交于 2021-01-28 07:50:40
问题 I have the next regular expression to find emojis on a text: re.compile(u'([\U00002600-\U000027BF])|([\U0001F300-\U0001F64F])|([\U0001F680-\U0001F6FF])') It is working well in Python 3 but in Python 2.7 I get this: sre_constants.error: bad character range How can I fix it to support both, Python 2.7 and Python 3? 回答1: Use r'(... instead of u'(... like this: re.compile(r'([\U00002600-\U000027BF\U0001F300-\U0001F64F\U0001F680-\U0001F6FF])') Also note that you can specify multiple ranges inside