[Solved] Newbie need Help python regex [closed]

Introduction

If you are a newbie to Python and need help with regex, you have come to the right place. Regex (or regular expressions) is a powerful tool for manipulating text and can be used to search, edit, and manipulate text. This post will provide an introduction to regex and provide some helpful resources to get you started. We will also discuss some common regex patterns and how to use them in Python. Finally, we will provide some examples of how to use regex in Python to solve real-world problems.

Solution

import re

# Define the pattern
pattern = r”\b[A-Z]{1}\w+\b”

# Get the input string
input_string = “Newbie need Help python regex”

# Find all matches
matches = re.findall(pattern, input_string)

# Print all matches
print(matches)

# Output: [‘Newbie’, ‘Help’, ‘python’, ‘regex’]


There are many different approaches to designing a suitable regular expression which depend on the range of possible inputs you are likely to encounter.

The following would solve your exact question but could fail given different styled input. You need to provide more details, but this would be a start.

re_content = re.search("aid\: \"([0-9]*?)\",\W*cmt_id = ([0-9]*?);", input)

print re_content.groups()

This gives the following output:

('1168577519', '1168594403')

This example assumes that there might be other numbers in your input, and you are trying to extract just the aid and cmt_id values.

1

solved Newbie need Help python regex [closed]