Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to find and replace an arrangement of 6 letters\special character\numbers.
For example they appear as such in my original code


The order in which the letters, numbers, and special character appear are always the same. I need to replace the _ (underscore) between CB3_09 with a - (hyphen).

I can easily find what I need using:

DEVICE_NAME","(.*_.*) (device)

but am having issues replacing the _ with a -.

share|improve this question

You can use capture groups to capture this format as 2 parts (the part before the special character and the part after), and just replace the special character between them:

Match: (DEVICE_NAME",".*?)_(.*? device)

Replace with: $1-$2

share|improve this answer
Search for:    `(DEVICE_NAME","[A-Z]{2}[0-9])_([0-9]{2} DEVICE)`
Replace with:  `\1-\2`

By being a little more specific with the search term you make sure you are replacing exactly what you want.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.