Hi! I am very new to regex and have been testing for hours to find an expression that works? I work in the VB.NET language, VS2015, Windows Forms, Win10.
I actually found a regex expression that appears to work for what I need on several regex tester sites (i.e. extract the picwgoal and pichgoal values independantly). But, it doesn't seem to be accepted in my project? Intellisense accuses that the ? cannot be used here? Then, the \b is separated like so, \ b... I'm guessing either the REGEX flavour isn't the correct one for VB.NET, or I just don't know how to use the expression?
I am working on a solution which converts RTF content in a RichTextBox to RTF markup code in a separate RTB. It also converts from RTF markup to display the original RTF document.
My goal is to extract both the picwgoal and pichgoal values from the test string below to display on 2 separate labels. Then, using a numeric up/down, resize these values by a percentage to scale the image down to size. Then, I need to replace the original picwgoal and pichgoal values with the new values (i.e. in twips) to resize/scale the image down to the required size. This works manually, but I would like to automate the task!
I have attempted using Regex.Match examples, but the problem seems to be the Regex expression itself? What I think I need to do, but don't know how, is:
- Search for picwgoal.
- Extract the numerical value (i.e. variable) which follows it.
- Scale the value down according to a user input percentage (i.e. using a numerical up/down).
- Replace the original value in the RTF markup with the new scaled down value.
- Repeat the operation for pichgoal (maybe both values can be replaced in a single operation???).
The test string is a partial extract from RTF markup code for an image and text!
If you are able to give me any pointers or help on this I would greatly appreciate it! I plan on posting the solution as soon as I get over the hurdles :-)
Thanks!!!
What I have tried:
' Step 1: create Regex.
Dim regex As Regex = New Regex("\d+")
Step 2: call Match on Regex.
Dim match As Match = regex.Match(?:picwgoal)(\d+)
' Step 3: test the Success bool.
' ... If we have Success, write the Value.
If match.Success Then
Console.WriteLine(match.Value)
End If
REGEX EXPRESSION: (?:picwgoal)(\d+)
TEST STRING:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}\viewkind4\uc1\pard\f0\fs17{\pict\wmetafile8\picw20793\pich13968\picwgoal11788\pichgoal7919 010009000003f88109000000e28109000000050000000b0200000000050000000c0290363951e2