Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-02-21
3
Medium Priority
?
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

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…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…

604 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