python --regex??

9 views
Skip to first unread message

bruce

unread,
Mar 30, 2018, 1:55:48 PM3/30/18
to lv...@googlegroups.com
hey...

anyone here with regex chops..

really basic regex question... i'm missing something..

x="MATH 59900/40 [47490] - THE "

need to extract MATH, 59900, and 40

a=re.match(r'(\D+).. gets the "MATH"...

but can't see how to get the rest of the string/groups..

cho...@gmail.com

unread,
Mar 30, 2018, 2:56:17 PM3/30/18
to lv...@googlegroups.com
Check put regexr.com, it’ll help with figuring out your regex.


chorgy
> --
> You received this message because you are subscribed to the Google Groups "LVL1 - Louisville's Hackerspace" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to lvl1+uns...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

d.s.

unread,
Mar 30, 2018, 3:12:53 PM3/30/18
to lv...@googlegroups.com
also this

  #!/usr/bin/python3
  import re

  x='MATH 59900/40 [47490] - THE'
  a=re.match(r'(\D+) (\d+)/(\d+) (\[\d+\]) - (\D+)', x)

  print a.group(1)
  print a.group(2)
  print a.group(3)
  print a.group(4)
  print a.group(5)


On Fri, Mar 30, 2018 at 11:56 AM, <cho...@gmail.com> wrote:
Check put regexr.com, it’ll help with figuring out your regex.


chorgy

> On Mar 30, 2018, at 10:55 AM, bruce <bado...@gmail.com> wrote:
>
> hey...
>
> anyone here with regex chops..
>
> really basic regex question... i'm missing something..
>
> x="MATH 59900/40 [47490] - THE "
>
> need to extract MATH, 59900, and 40
>
> a=re.match(r'(\D+)..  gets the "MATH"...
>
> but can't see how to get the rest of the string/groups..
>
> --
> You received this message because you are subscribed to the Google Groups "LVL1 - Louisville's Hackerspace" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to lvl1+unsubscribe@googlegroups.com.

bruce

unread,
Mar 30, 2018, 3:16:39 PM3/30/18
to lv...@googlegroups.com
On Fri, Mar 30, 2018 at 3:12 PM, d.s. <cho...@gmail.com> wrote:
> also this
>
> #!/usr/bin/python3
> import re
>
> x='MATH 59900/40 [47490] - THE'
> a=re.match(r'(\D+) (\d+)/(\d+) (\[\d+\]) - (\D+)', x)
>
> print a.group(1)
> print a.group(2)
> print a.group(3)
> print a.group(4)
> print a.group(5)
>


Hey...
Thanks... it was the last piece with the brackets...

for some reason \s[(\d+)\] didn't work..


>
> On Fri, Mar 30, 2018 at 11:56 AM, <cho...@gmail.com> wrote:
>>
>> Check put regexr.com, it’ll help with figuring out your regex.
>>
>> —
>> chorgy
>>
>> > On Mar 30, 2018, at 10:55 AM, bruce <bado...@gmail.com> wrote:
>> >
>> > hey...
>> >
>> > anyone here with regex chops..
>> >
>> > really basic regex question... i'm missing something..
>> >
>> > x="MATH 59900/40 [47490] - THE "
>> >
>> > need to extract MATH, 59900, and 40
>> >
>> > a=re.match(r'(\D+).. gets the "MATH"...
>> >
>> > but can't see how to get the rest of the string/groups..
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "LVL1 - Louisville's Hackerspace" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an email to lvl1+uns...@googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "LVL1 - Louisville's Hackerspace" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to lvl1+uns...@googlegroups.com.

cho...@gmail.com

unread,
Mar 30, 2018, 8:26:42 PM3/30/18
to lv...@googlegroups.com
A slash is missing from in front of the opening bracket in your snippet.


chorgy
Reply all
Reply to author
Forward
0 new messages