Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,752 questions

55,516 answers

573 users

How to check if a string includes $sometext$ without numbers in Python

1 Answer

0 votes
import re

def include_dollar_symbol_text(text: str) -> bool:
    # Regex to match $word$ (case-insensitive)
    cleaned_text = re.sub(r"\$[a-z]+\$", "", text, flags=re.IGNORECASE)

    # Check if any $ remains
    return "$" not in cleaned_text


print(include_dollar_symbol_text("abc xy $text$ z"))            # ok
print(include_dollar_symbol_text("abc xy $ text$ z"))           # space
print(include_dollar_symbol_text("abc xy $$ z"))                # empty
print(include_dollar_symbol_text("abc 100 $text$ z"))           # ok
print(include_dollar_symbol_text("abc $1000 $text$ z"))         # open $
print(include_dollar_symbol_text("abc xy $IBM$ z $Microsoft$")) # ok
print(include_dollar_symbol_text("abc xy $F3$ z"))              # include number
print(include_dollar_symbol_text("abc xy $text z"))             # missing close $



'''
run:

True
False
False
True
False
True
False
False

'''

 



answered Jul 11, 2025 by avibootz
...