2

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 -.

3

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

1
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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