RegExp Global Search
Posted
#1
(In Topic #1016)
Regular

Code (gambas)
- ' Use "gb.pcre"
- TextArea1.Text = myRegex.Text
Posted
Guru

<IMG src="https://www.cogier.com/gambas/Exif1.png">
</IMG>
Posted
Regular

cogier said
Is this what you are after?
No. The original mySubject is actually 115 lines of output from exiftool. I made a simplified example so it would be easier for others to try the code. I want to extract the lines beginning with "File Size", "Camera Model Name", "Image Size", "Megapixels" and "Shutter Speed". Other lines should be discarded.
My regex pattern works fine with an online tool such as RegExr: Learn, Build, & Test RegEx but I am unable get same results in Gambas.
There are other ways to solve this like doing a like comparison line by line in a for loop. But I would like to use regex for this, for the sake of learning how regex is used in Gambas.
Posted
Guru

/comp/gb.pcre/regexp - Gambas Documentation
Code (gambas)
- ' get disk I/O stats
Posted
Guru

ie…
exiftool -FileSize /file/path
exiftool -ImageSize /file/path
exiftool -CameraModelName /file/path
exiftool -ShutterSpeed /file/path
and so on.
or…
exiftool -FileSize -ImageSize -CameraModelName -ShutterSpeed /file/path
But for RegExp i think you want somethijng like this..
Code (gambas)
- ' list all the matches...
- TextArea1.Text &= myRegex[c].Text & "\n"
But it does not seem to work, maybe the pattern is not right?
Posted
Guru

Code (gambas)
- ' Gambas class file
- ''Requires gb.gui
- ''ExifTool needs to be installed
- Splitter1 As Splitter
- Splitter2 As Splitter
- FileChooser1 As FileChooser
- PictureBox1 As PictureBox
- BuildForm
- Splitter1.Layout = [50, 50]
- Splitter2.Layout = [75, 25]
- TextArea1.Text = sResult
- .Height = 800
- .Width = 1300
- .Arrangement = Arrange.Vertical
- .Padding = 5
- .Center
- .Arrangement = Arrange.Vertical
- .Alignment = Align.Center
<IMG src="https://www.cogier.com/gambas/ExifTest.png">
</IMG>
Posted
Regular

The patter is working elsewhere. I am using regex from grep for now:BruceSteers said
Maybe the pattern is not right?
Code
$ exiftool ~/Pictures/myphoto.jpg | grep -E '^((File Size)|(Camera Model Name)|(Image Size)|(Megapixels)|(Shutter Speed)).*'Code
File Size : 2.5 MB
Camera Model Name : OnePlus Nord 2T 5G
Shutter Speed Value : 1/50
Image Size : 3072x4096
Megapixels : 12.6
Shutter Speed : 1/50
Posted
Guru

the following will give the same result…
Code
exiftool -FileSize -Make -ImageSize -Megapixels -ShutterSpeed ~/Pictures/myphoto.jpg
(couldn't get -CameraModelName to work but -Make gave the same string)
It does not look like any of us here have had much experience using gb.pcre so cannot be much help on how to properly use it i'm afraid.
1 guest and 0 members have just viewed this.


