Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community of people that helps each other.

If you are beginner in IT field, you are more then welcome to ask questions, it will help you to learn faster. We are here to help you.

We are always beginner in something, we just need to remember it along the way.

there are no wrong questions - Ask Question

Regex - replace all character that is not a letter or number with underscore

0 contributions
11 points

Regex: 

(_)+|[^0-9A-Za-z]

Replace with:

_

Text before regex:

text to test(ooo)replace abc123 efg

Text after regex is applied:

text_to_test_ooo_replace_abc123_efg

Results screenshot from notepad plus plus

Regex - replace all chars that is not a letter or number with underscore - notepad plus plus screenshot
Notepad++ regex replace result

Alternative regexes

// Alternatively regex can be replaced with:

_+|\W

// what means:
// two or more _ character occurrences 
// or 
// any character that is not A-Z, a-z, 0-9, or _ 
// (\W is shortcat for [^A-Za-z0-9_])

Merged questions

  1. Regex - escape with underscore all characters that are not letter or number

0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more