Solved

How to code repeated regular expresion in VB.net for xml files

Posted on 2011-02-21
3
274 Views
Last Modified: 2013-11-26
Hello I am looking for a solution to simple VB.net coding issue.
The problem is easy to explain but difficult to code for novice like us.

We are making translation program in VB.net fot xml reporting files. Our
reporting database already include translation expression for every word which should be translated in our reports, which looks like: code.translate("WordToBeTranslated")
We have already decoded it into phase which get us back all WordToBeTranslated list from whole report. But only if textbox contain exactly one code.translate expression. We are using nodes and node list with regular expression.

This regular expresions and matching in VB code looks exactly like this:

New Regex("^=code.Translate\(\""(.*)\"")$"), RegexOptions.IgnoreCase)

m= pattern.Match(label)

So, if theres more than one code.translate, program gets back everything from first "quote" to the latest quote and is unable to detect each expression separately.

Please if you can give me any advice how to resolve this, I can really appreciate it ;)
Thanks,
Vojtech
0
Comment
Question by:psionic086
  • 2
3 Comments
 
LVL 8

Expert Comment

by:crysallus
ID: 34941808
This should probably help you understand what's going on, and give you a method to fix it (better than me simply giving you the solution as this way you're more likely to understand the solution).

http://www.regular-expressions.info/repeat.html
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 34943050
This is because you are using a greedy star. This will try to capture as much as possible that makes a valid match. What you want is the non-greedy version of the star--which you can achieve by adding a question mark after the star:

    New Regex("^=code.Translate\(\""(.*)\"")$"), RegexOptions.IgnoreCase)

However, I'd suggest rather than using dot-star, use "not quotation mark" to search:

    ew Regex("^=code.Translate\(\""([^"]*)\"")$"), RegexOptions.IgnoreCase)

Then, as long as a quote follows the string to find, you won't have to worry about greedy vs. non-greedy.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34943054
Forgot the question mark for Example 1:

    New Regex("^=code.Translate\(\""(.*?)\"")$"), RegexOptions.IgnoreCase)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now