Python Forum
Having trouble with regular expressions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Having trouble with regular expressions
#1
Hi I am a new python learner, having some difficulty with regular expressions

import re

x='trash bag 19th of July 1.456 3x times 20 juice'

y=re.findall('[0-9]+[0-9]',x)

print(y)
Here is the result: ['19','456','20']

I was doing some testing looking to understand regular expressions, I wrote the code and I thought it would not retrieve any numbers. When I run the code, why does it retrieve them? The way I wrote it, I thought that if a number is not followed by another number it wouldn't be retrieved.

Do I understand this correctly: "is 1 a number? yes. is 9 a number? yes. is "t" a number"? no -> no match

I also don't understand it retrieves the "19" but does not retrieve "1".

Sorry if this is a stupid question, I'm really new at this
Reply


Messages In This Thread
Having trouble with regular expressions - by mikla - Mar-16-2021, 01:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Use or raw string on regular expressions Zaya_pool 5 305 May-09-2024, 06:10 PM
Last Post: Zaya_pool
Information Do regular expressions still need raw strings? bobmon 3 340 May-03-2024, 09:05 AM
Last Post: rishika24
  Recursive regular expressions in Python risu252 2 1,338 Jul-25-2023, 12:59 PM
Last Post: risu252
Sad Regular Expressions - so close yet so far bigpapa 5 1,047 May-03-2023, 08:18 AM
Last Post: bowlofred
  Regular Expressions pprod 4 3,144 Nov-13-2020, 07:45 AM
Last Post: pprod
  Format phonenumbers - regular expressions Viking 2 1,957 May-11-2020, 07:27 PM
Last Post: Viking
  regular expressions in openpyxl. format picnic 0 2,521 Mar-28-2020, 09:47 PM
Last Post: picnic
  Unexpected (?) result with regular expressions guraknugen 2 2,276 Jan-18-2020, 02:33 PM
Last Post: guraknugen
  Strange output with regular expressions newbieAuggie2019 1 1,957 Nov-04-2019, 07:06 PM
Last Post: newbieAuggie2019
  Regular Expressions amitalable 4 2,807 Mar-14-2019, 04:31 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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