python regex for extracting strings between certain two strings

Mansumen

Let's assume I have a string

st = "'aaa': '1', 'bbb': '2.3', 'ccc': 'name'"

I want to extract from st the following

['1', '2.3', 'name']

How can I do this?

Thanks

MYGz

Doing it with ast module would be best, like jezrael did it. Here is another solution with regex:

import re

st = "'a': '1', 'b': '2.3', 'c': 'name', 'd': 229, 'e': '', 'f': '228', 'g': 12"
print re.findall(r'\'\S+?\':\s*\'?(.*?)\'?(?:,|$)', st)

Output:

['1', '2.3', 'name', '229', '', '228', '12']

Demo on regex101:

https://regex101.com/r/zGAt4D/5

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Extracting a string between other two strings in R

分類Dev

Extracting a string between other two strings in R

分類Dev

Extracting a string between other two strings in R

分類Dev

Extracting a string between other two strings in R

分類Dev

Regex: Match all characters between two strings

分類Dev

Finding text between two strings while containing a certain value

分類Dev

Python3 toggle between two strings

分類Dev

Regex Find email address between First Two Instances of Strings

分類Dev

regex command line linux - select all lines between two strings

分類Dev

Regex discard catch between strings

分類Dev

combine two strings in python

分類Dev

Common strings between two sequences

分類Dev

Getting strings between certain string and a special character

分類Dev

Extracting sub strings in order

分類Dev

Extracting Strings Containing Spaces

分類Dev

Extracting two values from python regex

分類Dev

Python Diferences between lines of strings

分類Dev

How to ignore strings where a specific pattern occurs between two strings?

分類Dev

Getting the common character count between two strings

分類Dev

Replace all occurrences of a character between two strings

分類Dev

How to get everything in between these two strings?

分類Dev

Extract text in between two strings if a sub-string present in between those two strings

分類Dev

Capitalizing certain strings in an array

分類Dev

Merge two large strings in python efficiently

分類Dev

Python: Symmetrical Difference Between List of Sets of Strings

分類Dev

How to count length of list with conditional exclusion of certain strings and numbers? Python

分類Dev

Deleting text between two strings in php using preg_replace

分類Dev

How to select a string between two strings in a column in SQL Server?

分類Dev

Generate range between two strings [AA] -> [CD] or [CCC] -> [DMK]

Related 関連記事

  1. 1

    Extracting a string between other two strings in R

  2. 2

    Extracting a string between other two strings in R

  3. 3

    Extracting a string between other two strings in R

  4. 4

    Extracting a string between other two strings in R

  5. 5

    Regex: Match all characters between two strings

  6. 6

    Finding text between two strings while containing a certain value

  7. 7

    Python3 toggle between two strings

  8. 8

    Regex Find email address between First Two Instances of Strings

  9. 9

    regex command line linux - select all lines between two strings

  10. 10

    Regex discard catch between strings

  11. 11

    combine two strings in python

  12. 12

    Common strings between two sequences

  13. 13

    Getting strings between certain string and a special character

  14. 14

    Extracting sub strings in order

  15. 15

    Extracting Strings Containing Spaces

  16. 16

    Extracting two values from python regex

  17. 17

    Python Diferences between lines of strings

  18. 18

    How to ignore strings where a specific pattern occurs between two strings?

  19. 19

    Getting the common character count between two strings

  20. 20

    Replace all occurrences of a character between two strings

  21. 21

    How to get everything in between these two strings?

  22. 22

    Extract text in between two strings if a sub-string present in between those two strings

  23. 23

    Capitalizing certain strings in an array

  24. 24

    Merge two large strings in python efficiently

  25. 25

    Python: Symmetrical Difference Between List of Sets of Strings

  26. 26

    How to count length of list with conditional exclusion of certain strings and numbers? Python

  27. 27

    Deleting text between two strings in php using preg_replace

  28. 28

    How to select a string between two strings in a column in SQL Server?

  29. 29

    Generate range between two strings [AA] -> [CD] or [CCC] -> [DMK]

ホットタグ

アーカイブ