Click here to Skip to main content
14,330,663 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi
I have a vb app that use regex with a textbox that user put his pattern.

And another textbox for app output.

The app using matches , split , replace methods.

The output of matches method
Always work ok with the regexoptions.

But split and replace methods
Sorks ok with regexoptions only
When they are running after
The matches method.

If they are running first without
Previously running matches method
The results are always according
To the last regexoptions of the previous matches method.

Can someone help.
Thanks in advance.


[edit]
Added as a solution:
Quote:
That's the problem the code
Run ok. The app not throw any errors.

The results are ok but without
Related to the current regexoptions

Only the results of the matches
Method are related to the regexoptions.

Thank you.

[/edit]

What I have tried:

Re include regexoptions

re.matche (source)

Re.replace(source, replacement)

Re.split(source)
Posted
Updated 8-Oct-19 2:41am
v2
Comments
Richard MacCutchan 8-Oct-19 5:36am
   
"Can someone help."
Not unless you show the actual code and explain where it is failing.
OriginalGriff 8-Oct-19 6:17am
   
"That's the problem the code
Run ok. The app not throw any errors."
No, it doesn't - it just doesn't throw any exceptions, which means it "doesn't crash". That doesn't mean it's right, or it would do what you expected! "Correct code" doesn't just mean "it compiled ok and doesn't crash"!

Think of the development process as writing an email: compiling successfully means that you wrote the email in the right language - English, rather than German for example - not that the email contained the message you wanted to send.
Running without actually crashing is like having valid English sentences in there - that's not the same as "meaning what you wanted to say".
Correct code is "written in English", and "means what you wanted to say" - and that's a big difference!

So now you enter the second stage of development (in reality it's the fourth or fifth, but you'll come to the earlier stages later): Testing and Debugging.

Start by looking at what it does do, and how that differs from what you wanted. This is important, because it give you information as to why it's doing it. For example, if a program is intended to let the user enter a number and it doubles it and prints the answer, then if the input / output was like this:
Input   Expected output    Actual output
  1            2                 1
  2            4                 4
  3            6                 9
  4            8                16
Then it's fairly obvious that the problem is with the bit which doubles it - it's not adding itself to itself, or multiplying it by 2, it's multiplying it by itself and returning the square of the input.
So with that, you can look at the code and it's obvious that it's somewhere here:
private int Double(int value)
   {
   return value * value;
   }

Once you have an idea what might be going wrong, start using the debugger to find out why. Put a breakpoint on the first line of the method, and run your app. When it reaches the breakpoint, the debugger will stop, and hand control over to you. You can now run your code line-by-line (called "single stepping") and look at (or even change) variable contents as necessary (heck, you can even change the code and try again if you need to).
Think about what each line in the code should do before you execute it, and compare that to what it actually did when you use the "Step over" button to execute each line in turn. Did it do what you expect? If so, move on to the next line.
If not, why not? How does it differ?
Hopefully, that should help you locate which part of that code has a problem, and what the problem is.
This is a skill, and it's one which is well worth developing as it helps you in the real world as well as in development. And like all skills, it only improves by use!


We can;t tell what you did without the relevant code fragment: we have no idea what code you actually wrote that you expected to do what you wanted. And without that, we have no idea how to help you fix it!

So edit your question, paste in the relevant code fragment - no more than the method that contains your regex code - and we'll see what we can do. But without that? we really, really can't help you at all...
Member 13569650 8-Oct-19 7:52am
   
Ohh I got out from my frustration
Before calling matches method
I called getregexoptions function

But before calling split and replace
I forgot to call getregexoptions.

Thank you.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 2

As mentioned in the comments, you were able to resolve this on your own by calling getregexoptions first.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100