How to check with regex for special letters?

Member

by jerad , in category: Third Party Scripts , 3 months ago

How to check with regex for special letters?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by scotty_walker , 3 months ago

@jerad 

To check for special letters using regular expressions (regex), you can use the following pattern:

1
[^a-zA-Z0-9s]


This pattern will match any character that is not a letter (upper or lower case), a number, or a whitespace character.


Here is an example using Python to check for special letters in a string:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import re

def check_special_letters(text):
    pattern = re.compile(r'[^a-zA-Z0-9s]')
    special_letters = pattern.findall(text)
    
    if special_letters:
        print("Special letters found:", special_letters)
    else:
        print("No special letters found")

text = "Hello, world! This is a test 123."
check_special_letters(text)


In this example, the text "Hello, world! This is a test 123." is checked for special letters using the regex pattern. The function will output the special letters found in the text.

Related Threads:

How to capture same letters with regex?
How to delete brackets after a special letter in regex?
How to check the phone number using regex?
How to pull spanish letters from teradata?
How to create pagination with letters using codeigniter?
How to know if an attribute contains non letters characters in oracle?