Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What regex would I use to get urls that follow this pattern:
'https://www.facebook.com/' + 'some text' + 'browser'
Meaning that it starts with the facebook url, has some text which varies, and then has the word 'browser' at the end?
Thanks!
r'https://www\.facebook\.com/.*browser'
. is a regex metacharacter meaning "any single character", so the literal periods have to be escaped with backslashes. * means "any number of matches for the previous thing", so .* means "any number of arbitrary characters". The r in front of the string marks it as a raw string literal, so backslashes are processed by the regex engine instead of the Python parser.
I think it is r'https://www\.facebook\.com/.*browser$' , because the word 'browser' is at the end.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 months ago.
Improve this question
What is wrong with the below used regular expression? Why does it not match the password?
import re
pattern = re.compile ('^\w##$%{8,}')
password = '12345abcd##$%'
x = pattern.search(password)
print (x)
print (len(password))
You didn't escape the $ which has a special meaning in a regular expression and didn't put the allowed characters in square brackets to allow any of them.
This: ^[\w##\$%]{8,} is the modified version of the regex which matches the password.
Escaping the $ character isn't really necessary within square brackets so ^[\w##$%]{8,} will work as well.
I suggest you check your regular expressions here: https://regex101.com/r/ldvJLf/1 . This site explains in detail the meaning of all single elements of the regular expression, so you can directly see what is wrong if things doesn't work as you expected.
Tip:
check your regexes online https://regexr.com/
I think you want:
pattern = re.compile ('^[\w##$%]{8,}')
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I would like to extract some strings from between quotes using regular expression. The text is shown below:
CCKeyUpDomReady('test.asmx/asdasd', 'QMlPJZTOH09XOPCcbB2jcg==', '0OO6h+G2Tzhr5XWj1Upg0A==', '0OO6h+G2Tzhr5XWj1Upg0A==', '/qqwweq2.asmx/qqq')
Expected result must be:
test.asmx/asdasd
/qqwweq2.asmx/qqq
How can I do it? Here is the platform for testing:
https://regexr.com/3n142
The criteria: string which is between quotes must contains "asmx" word. The text is much more than showed above. You can think like that you are searching asmx urls in a website source code.
See regex in use here
'((?:[^'\\]|\\.)*asmx(?:[^'\\]|\\.)*)'
' Match this literally
((?:[^'\\]|\\.)*asmx(?:[^'\\]|\\.)*) Capture the following into capture group 1
(?:[^'\\]|\\.)* This is a beautiful trick gathered from PhiLho's answer to Regex for quoted string with escaping quotes. It matches escaped ' or any other character.
asmx The OP's search string/criterion
(?:[^'\\]|\\.)* This again
' Match this literally
The result is in capture group:
test.asmx/asdasd
/qqwweq2.asmx/qqq
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
Why Python's re module escapes semicolon characters?
print(re.escape('text;text'))
gives me the following output:
text\;text
>>> re.escape.__doc__
'Escape all non-alphanumeric characters in pattern.'
It escapes ;(semicolon), because ; is not an alphanumeric character.
It escapes a semicolon because that is what it's designed to do. As per the docs, it escapes all non-alphanumeric characters.
Return string with all non-alphanumerics backslashed; this is useful if you want to match an arbitrary literal string that may have regular expression metacharacters in it.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm a Python and regex noob. I managed to get a full page of html source into the command line by the following statement.
print (driver.page_source).encode('utf-8')
Cool. But there are some predictable strings in that text that I need to extract and store into an array. The string pattern being looked for is, [4 numbers] followed by a [hyphen] followed by between 1 and 5 numbers, e.g.:
2013-80324 or 2013-03 but not 2013-832888
Thanks for any help.
(?:^|(?<=\D))\d{4}-\d{1,5}(?=\D|$)
?: denotes a non capturing group
^ matches the pattern at start of string (though unlikely for HTML input)
$ mathces the pattern at the end of string
\d denotes a digit [0-9] and \D a non-digit
{n} is a quantifier for length n
{m,n} quantifies a length of range m to n (both inclusive)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a file and some substitution is needed: replace "," with "," and all other characters not in rule2 with a whitespace, how can I do that?
What about this?
text = text.replace(",", ",")
You can use the regular expressions module:
text = re.sub(',', ',', text)
text = re.sub(negated_rule2, ' ', text)
where your negation of "rule2" is formatted using the regular expressions syntax (see link above).