Extract text from file using regex

There is a file called “perf.js” which the following text inside it:


I’m trying to extract the:


So that it will be $uBlockUUID variable

But because it has " and \ and } I’m having trouble with this.

Hi afbebn, welcome to the forum!

What sort of trouble are you having? Please provide what you’re attempting as well as any errors. (formatted as code, please. Use the </> icon) This will allow us to help you. I look forward to your update!

The “problem” is just extracting it, the rest I already completed,
uh my bad I wasn’t explaining what I was doing,
I basically have a script to install some firefox extenstions without user interactions, since firefox blocked side loading a while ago the only option is doing it using a script.
Installing uBlock extenstion is already done, I just need a way that will extract the UUID, using that to open the settings page and then restore a backup file (most of the work is done), the only part I would like to improve with this script is that instead of manually clicking the ublock extenstion icon and getting into settings page this way - I would love to have the UUID and using that to automatically open the settings page.

Here is my attempt, but this is not catching the UUID, but all of the setting inside this line

$Current1 = Get-ChildItem -Directory -Path "$env:APPDATA\Mozilla\Firefox\Profiles" -Filter '*.default-release'
$Current = "$env:APPDATA\Mozilla\Firefox\Profiles\$Current1"
Select-String -Path $Current\prefs.js -Pattern $ublock

Found something but it’s super ugly I hate it, can someone help me over here?

$Current1 = Get-ChildItem -Directory -Path "$env:APPDATA\Mozilla\Firefox\Profiles" -Filter '*.default-release'
$Current = "$env:APPDATA\Mozilla\Firefox\Profiles\$Current1"
$file   = get-content "$Current\prefs.js"
$webmid = $file | select-String -Pattern $ublock |
 foreach {$_.matches.value}
 write-host "$webmid"

I’m basically finished I just need a better regex, I’m not the best at regex, if someone can help me with this it would be wonderful and I will finally get on with my life.

Please don’t get me wrong - but have you tried to search for it? In the vast majority of the cases you’re not the very first one with a given task. So it is pretty likely that someone already mastered the same or a similar challenge and shared it with the world.

When I search for "powershell regex uuid" - powershell regex uuid - Google Search there are more than enough hits with promising examples of code snippets …

for example:



I did try to search, of course, and those links are for GUID in a simple text, I have multiple GUID in this text and need to extract only one, which can only be done using regex, and I’m not good with regex, that’s the problem.

My prefs.js doesn’t have that in it even though I have the extension so I had to make up a file to test. I can see the problem you have is that you need to select that specific GUID so you just need to make sure it’s preceded by the uBlock stuff. Try this pattern:


For an explanation of the regex, paste it into https://regex101.com

You don’t need to use Get-Content with Select-String in fact it should perform way faster if you don’t. To extract the GUID:

$path = 'C:\users\blah\prefs.js'
$pattern = 'uBlock.+?([a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12})\\'
(Select-String -Pattern $pattern -Path $path).Matches.Groups[1].Value
1 Like

Finally, thank you!!!
Just one more question - how do I make it as $uBlockUUID variable?
Edit, nvm you just add $blabla in front of the (select-string) row.