Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

DEVICE_NAME","CB2_02 DEVICE, DEVICE_NAME","CB3_09 DEVICE, DEVICE_NAME","OB6_12 DEVICE...

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
add comment

2 Answers 2

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
add comment
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
add comment

Your Answer

 
discard

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.