简体   繁体   中英

Regex for ampersand, alphabetic characters and equal sign in python

I am looking for a Regex which will enable me to find something like &dog= or &entropy= in a string, I tried something like

&+s*^[a-zA-Z]+s*=

believing that I could separate the things I want with the s* but that didn't work out so well, any help would be appreciated. Thanks!

Im gonna go out on a ledge and assume

from urllib import urlparse
urlparse.parse_qs(my_query_string)
#or 
urlparse.urlparse(my_url_string)[3]

is what you really want

If you want to use a regex you can use something like this:

&\w+=

Working demo

Code

import re
p = re.compile(ur'&\w+=')
test_str = u"asdfasdf&asdf=asdfffff&abc123=asdf\n\n\n"

re.findall(p, test_str)

If you want to capture the value you can use capturing groups like this:

&(\w+)=

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM