0

I have a string

" request.addParameter('page','/TMRMKUOHY/RPM/Store/srrreVkew.jsp?resODFlag','N','',true,false); ".

I want to extract the part

" '/TMRMKUOHY/RPM/Store/srrreVkew.jsp?resODFlag' "

out of this string. I tried several combinations of regex (using re module in python) but can't find the exact desired pattern that gives me the substring out of the main string.

nu11p01n73R
26.8k3 gold badges43 silver badges52 bronze badges
asked Oct 31, 2014 at 6:58
7
  • 1
    Can you put those combinations of regex that you tried into your question? Commented Oct 31, 2014 at 6:59
  • Does the string always begin with a / Commented Oct 31, 2014 at 7:04
  • pat = re.search("\'\/[a-z]*[A-Z]*[./+]",string1) pat = re.search("\'\/(.+)\?(.\w)",string1) pat = re.search("\'\/(.+)?(.\w*)",string1) pat = re.search("\'\/(.+)?(.\W*)",string1) pat = re.search("\'\/(.+)?(\w*\d*)\'",string1) pat = re.search("\'\/(.+)?(\w*\d*)\'[^,]",string1) pat = re.search("\'\/(\w+)?'",string1) Commented Oct 31, 2014 at 7:04
  • @Harvey In the question please, not in comments. You can edit your question and add that at the end. Commented Oct 31, 2014 at 7:04
  • @nu11p01n73R It begins with a single quote followed by / Commented Oct 31, 2014 at 7:07

4 Answers 4

1
'([^']+)'

You can try this.

Do print re.findall(r"'([^']+)'",x)[1].

Here x is your string.Basically it is extracting the second group.

See demo.

http://regex101.com/r/yG7zB9/2

answered Oct 31, 2014 at 7:02
Sign up to request clarification or add additional context in comments.

1 Comment

I didn't. In fact you're a STAR.
0

Use the regex

'\/[^']+'

The code can be written as

x=" request.addParameter('page','/TMRMKUOHY/RPM/Store/srrreVkew.jsp?resODFlag','N','',true,false); ".
re.findall(r"'\/[^']+'", x)"
["'/TMRMKUOHY/RPM/Store/srrreVkew.jsp?resODFlag'"]

see how the regex works http://regex101.com/r/pK9mI8/1

you can also use search function to search and find the substring matching the pattern as

 re.search(r"'\/[^']+'", x).group()
"'/TMRMKUOHY/RPM/Store/srrreVkew.jsp?resODFlag'"
answered Oct 31, 2014 at 7:08

Comments

0

Seems like you want something like this,

>>> import re
>>> s = " request.addParameter('page','/TMRMKUOHY/RPM/Store/srrreVkew.jsp?resODFlag','N','',true,false); "
>>> re.search(r"'(/[^']*)'", s).group(1)
'/TMRMKUOHY/RPM/Store/srrreVkew.jsp?resODFlag'
answered Oct 31, 2014 at 7:09

Comments

0

You are not forced to use regex you can use split():

>>> s.split(',')[1]
"'/TMRMKUOHY/RPM/Store/srrreVkew.jsp?resODFlag'"
answered Oct 31, 2014 at 7:13

1 Comment

yep, for extract a substring you can use some ways that regex is one of them , so if you find this answer useful you can tell this to community by up voting ,

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.