?
Solved

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

Posted on 2011-02-21
3
Medium Priority
?
281 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

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…
Suggested Courses

770 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