tinycodinglm / code /code031.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 12)
3c88a0f verified
|
Raw History Blame Contribute Delete
2.18 kB
deepseek-harness trace
System You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing c...

You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies.

User

What are regular expressions and how do I use them?

Assistant

Basic Patterns:

python
import re

# Literal match
re.findall(r"cat", "cat bat sat")  # ['cat']

# Any character (except newline)
re.findall(r".at", "cat bat sat")  # ['cat', 'bat', 'sat']

# Digit
re.findall(r"\d", "abc123")  # ['1', '2', '3']

# Word character (letter, digit, underscore)
re.findall(r"\w+", "hello world")  # ['hello', 'world']

# Whitespace
re.findall(r"\s", "a b c")  # [' ', ' ']

Quantifiers:

python
re.findall(r"ab*c", "ac abc abbc")  # ['ac', 'abc', 'abbc']
re.findall(r"ab+c", "ac abc abbc")  # ['abc', 'abbc']
re.findall(r"ab?c", "ac abc")  # ['ac', 'abc']
re.findall(r"ab{2}c", "abc abbc")  # ['abbc']

Anchors:

python
re.findall(r"^hello", "hello world")  # ['hello'] (start)
re.findall(r"world$", "hello world")  # ['world'] (end)

Character Classes:

python
re.findall(r"[aeiou]", "hello")  # ['e', 'o']
re.findall(r"[a-z]", "Hello")  # ['e', 'l', 'l', 'o']
re.findall(r"[^0-9]", "abc123")  # ['a', 'b', 'c']

Groups:

python
re.findall(r"(\d+)-(\d+)", "123-456")  # [('123', '456')]
re.search(r"(\d+)", "abc 123 def")  # <Match: '123'>

Common Patterns:

python
# Email (simple)
re.findall(r"[\w.+-]+@[\w-]+\.[\w.]+", text)

# Phone number
re.findall(r"\d{3}-\d{3}-\d{4}", text)

# URL
re.findall(r"https?://\S+", text)