Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regex not specific enough
#6
(Mar-23-2019, 05:27 AM)DeaD_EyE Wrote: Try this regex:
reg = r'"GET \S+'
This makes a lot of sense to me. I read this as after the string '"GET ', return the first string of characters of size one or more until a space is hit. Is it possible to have this method return the second quotation mark?

(Mar-23-2019, 04:31 PM)ichabod801 Wrote: I would use a non-greedy regex:

re.findall('\"GET .+?\"', entry)
Regexes by default will get as much as possible, returning the largest possible match (they're greedy). The ? makes things like + and * stop at the first possible match.

As usual, ichabod, you have great advise. Unlike DeaD_EyE's solution yours returns the second quotation mark. My follow up question. Is there a situation where your solution would return a different solution than DeaD_EyE's? Other than the second quotation mark, that is.

Thanks to you both.
Reply


Messages In This Thread
Regex not specific enough - by Clunk_Head - Mar-23-2019, 03:47 AM
RE: Regex not specific enough - by woooee - Mar-23-2019, 05:26 AM
RE: Regex not specific enough - by Clunk_Head - Mar-23-2019, 02:52 PM
RE: Regex not specific enough - by DeaD_EyE - Mar-23-2019, 05:27 AM
RE: Regex not specific enough - by ichabod801 - Mar-23-2019, 04:31 PM
RE: Regex not specific enough - by Clunk_Head - Mar-23-2019, 05:32 PM
RE: Regex not specific enough - by woooee - Mar-23-2019, 05:42 PM
RE: Regex not specific enough - by Clunk_Head - Mar-23-2019, 05:44 PM
RE: Regex not specific enough - by ichabod801 - Mar-23-2019, 06:27 PM
RE: Regex not specific enough - by DeaD_EyE - Mar-24-2019, 07:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Delete specific lines contain specific words mannyi 2 4,188 Nov-04-2019, 04:50 PM
Last Post: mannyi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020