This question already has answers here:
Difference between * and + regex
(7 answers)
Using explicitly numbered repetition instead of question mark, star and plus
(4 answers)
Closed 3 years ago.
I have a string like:
[10/Jul/2019:00:45:18 +0900] "POST /auth/identity/success HTTP/1.1"
I want to extract everything inside ""
for the date I used
re.compile('\[(\d+\/\w\w\w\/\d\d\d\d:\d\d:\d\d:\d\d\s\+\d\d\d\d)\]')
for the string inside "" instead of matching one by one I am hoping if there is way to match say 10 character with one regex command.
I've done re.compile('(\"[A-Z]\s[\w\/]\s[\w\/\"])')
What I am trying to do:
\" matches "
[A-Z] matches 4 character (but actually match only one character)
\s for whitespace
[\w\/] for matching everything in /auth/../success
[\w\/\"] for HTTP/1.1"
Related
This question already has answers here:
Replacing instances of a character in a string
(17 answers)
Closed 7 months ago.
I am requesting an API which sometimes gives a string that contain "*" characters.
I have to post the output on discord, where ** makes the text bold.
I want to see if a string contains any * and if so put a markdown \ escape character in front of the *.
How can I accomplish this?
As #Random Davis rightly pointed out in the comments, you can use str.replace("*","\*")and it will replace all the * occurrence.
This question already has answers here:
Exclude characters from a character class
(5 answers)
Closed 2 years ago.
For example, I want to replace all the data going from the specified intervals with * (except the chars u0650, u0660, u064F), for example.
Note: I don't want to break the interval because I have a lot of characters to preserve.
data = re.sub(r'[\u0600-\u061E\u0620-\u065F\u0670-\u06ef]', "*", data)
You can put the characters to be excluded in a negative Lookahead before the main character class.
For example:
(?![\u0650\u0660\u064F])[\u0600-\u061E\u0620-\u065F\u0670-\u06ef]
Demo.
This question already has answers here:
Regular expression to match a line that doesn't contain a word
(34 answers)
Closed 3 years ago.
I'm trying to write a regex that filters out matches if they contain "plex" in them.
plex-release -> should not match
my-release -> should match
potato -> should match
Been playing with pythex and came up with this one that works partially:
(?![plex])(\w+)[-_](release|version)$
However this also messes with any other values containing the letter "p".
I'm trying to come up with a regex that leaves out matches that only contain the string "plex" and in this order, not just any letter from the string.
Yes, you can do it using this regex.
^((?!plex).)*$
Source : Regular expression to match a line that doesn't contain a word
This question already has answers here:
Regular expression to match a dot
(7 answers)
Closed 3 years ago.
I am getting an address string from the client (first I check that it is a string under a certain length), and I have this so far: ^[a-zA-Z0-9 ]+$ but it will fail if the address has a "." char in it.
I want a single regex that also matches if a "." char shows up: the address can only contain spaces, numbers and letters.
Obviously, one can do if "." in address_string, but I am trying to do my check in one regex match.
How do I also escape/search for a "." char in a string?
Just put in an escape character:
^[a-zA-Z0-9 \.]+$
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 4 years ago.
I have a question about the positioning of the "do not include operator in regex in python" shown below
[^]
If I have the following expression
print(re.findall(r'^[^_][-\w\d]+[^:/)]$',x))
does it matter where i place [^:/)] or will it only exclude : and / at the end of the string since i placed it at the end
With the $ at the end of your regular expression you've anchored the [^:/)] character group to only match at the end of the string. Any matches must end with [^:/)].