Home > Software design >  Notepad Search for and replace Underscore Characters in "GUIDs"
Notepad Search for and replace Underscore Characters in "GUIDs"

Time:10-02

A colleague has written some C# code that outputs GUIDs to a CSV file. The code has been running for a while but it has been discovered that the GUIDs contain underscore characters, instead of hyphens :-(

There are several files which have been produced already and rather than regenerate these, I'm thinking that we could use the Search and Replace facility in Notepad to search across the files for "GUIDs" in this format: {89695C16_C0FF_4E7C_9BB2_8B50FAC9D371} and replace it with a properly formatted GUID like this: {89695C16-C0FF-4E7C-9BB2-8B50FAC9D371}.

I have a RegEx to find the offending GUIDs (probably not very efficient):

(([A-Z]|[0-9]){8}_)(([A-Z]|[0-9]){4})_(([A-Z]|[0-9]){4})_(([A-Z]|[0-9]){4}_(([A-Z]|[0-9]){12}))

but I don't know what RegEx to use to replace the underscores with. Does anybody know how to do this?

CodePudding user response:

You can use the following solution:

Find What: (?:\G(?!\A)|{(?=[a-f\d]{8}(?:_[a-f\d]{4}){4}[a-f\d]{8}\}))[a-f\d]*\K_
Replace with: -
Match case: OFF

See the settings and demo:

enter image description here

See the enter image description here

  • Related