This question already has answers here:
How to grab number after word in python
(4 answers)
Closed 2 months ago.
I would recieve text like below
CRM NO: 23542536 crmno:# 3542536 crmno:_ 3542536... crm no 43653768754
my desired output will be:
23542536
3542536
3542536
43653768754
I want to write a regex to extract only the number after the string 'CRM NO'.
Also the CRM NO will come in variations like CRM NO or crmno or crm no
I have tried the regex ((?<=CRM NO)\D+\d+) but not compatible with all the entries
You can use a capture group with a case insensitive match and then match the leading part with an optional space
(?i)\bCRM ?NO\D+(\d+)\b
Regex demo
Related
This question already has answers here:
How do I validate a date string format in python?
(5 answers)
Closed 6 months ago.
Im trying to check if a user's input is following the pattern integer/integer/integer(like month/day/year) but i dont know how to use exactly the match function to define that the pattern contains "number",then "/",again "number" and "/"...
Check out https://regex101.com/ for a neat website to check your regex! This is implemented in python using the re library. https://docs.python.org/3/library/re.html
In your case, the pattern would be [0-9]{1,2}\/[0-9]{1,2}\/[0-9]{2,4}
This question already has answers here:
regex for zip-code
(3 answers)
Closed 2 years ago.
I'm trying to write a regex that follows these constraints:
Exactly 5 digits
Sometimes, but not always, followed by a dash with 4 more digits
Zip code needs to be preceded by at least one whitespace
Cannot be at the start of a text
I've arrived at this but it's not giving me the output I want:
r"^[A-Za-z].*\s.*\d{5}(?:[-\s]\d{4})?$"
I would use:
(?<=[ \t])((?:\d{5}(?=[^\d-]|$))|(?:\d{5}-\d{4}(?=[^\d-]|$)))
Demo and explanation
This question already has answers here:
How to use regex to find all overlapping matches
(5 answers)
Closed 2 years ago.
I have text as below-
my_text = "My telephone number is 408-555-1234"
on which i am searching the pattern
re.findall(r'\d{3}-\d{1,}',my_text)
My intention was to search for three digit numeric value followed by - and then another set of one or more than one digit numeric value. Hence I was expecting the result to be - ['408-555','555-1234'],
However the result i am getting os only ['408-555'] .
Could anyone suggest me what is wrong in my understaning here. And suggest a pattern that would serve my purpose
you can use:
re.findall(r'(?=(\d{3}-\d+))', my_text)
output:
['408-555', '555-1234']
This question already has answers here:
Python regex with question mark literal
(5 answers)
Closed 4 years ago.
Am working on a data set with a column next review date. This column have missen fields represented by a question mark(?)
I want to capture this ? with a regular expression then seperate all rows with no review date from the rest of the data.
Question: What is the expression to distinctly match a question mark? (?)
Backslash before question mark means "literally match a question mark"
\?
Also, putting a question mark into a character class will mean it's matched literally rather than having its typical "0 or 1 of the previous" meaning
[?]
Thus:
bcd[?]
bcd\?
Will both match data that looks like:
abcd?efg
^^^^
If you want to match data that is just a question mark and nothing else, use the start ^ and end $ markers:
^\?$
Consider though that it may be faster not to use regex and just do a simple "string contains" check for the presence of a question mark if that's literally all you're doing, and don't require complex pattern matching and value capture
This question already has answers here:
My regex is matching too much. How do I make it stop? [duplicate]
(5 answers)
Regex to first occurrence only? [duplicate]
(4 answers)
Closed 4 years ago.
I want to extract all occurrences of a pattern in Python.
Here is what i have done
import re
string="Any information <p>sent to the server as clear text</p>, may be stolen and used later for <p>identity theft</p> or user impersonation. In addition, several privacy regulations state that sensitive information such as user<p> credentials will always be sent encrypted </p> to the web site."
regex='<p>.*</p>' # obviously it matches starting <p> to the last </p>
if re.findall(regex, String):
print(re.findall(regex, string))
else:
print('no match found')
I want to extract all the occurance of paragraph tags. I mean the output should be a list which looks like this
['<p>sent to the server as clear text</p>', '<p>identity theft</p>', '<p> credentials will always be sent encrypted </p>']
I've found few similar questions but not serving the purpose
Find all occurrences of a substring in Python
Finding multiple occurrences of a string within a string in Python
change your regex like this :
regex=r"<p>.*?</p>"
It gives o/p like :
['<p>sent to the server as clear text</p>', '<p>identity theft</p>',
'<p> credentials will always be sent encrypted </p>']