2
<option value="28.5.2011|2">28.maj. 2 dni od 109,00&nbsp;EUR</option>
<option value="27.8.2011|2">27.avg. 2 dni od 109,00&nbsp;EUR</option>
ect

i need to parse data from text like this.

I need to get in first example:

109

in second example:

109

regular expression must be generic to get this data becous ei have 1000 rows.

To get 27.8.2011 i use split and | for delimeter. The same with 2. but i do not know how to get 109.

Thx

senzacionale
  • 20,448
  • 67
  • 204
  • 316

2 Answers2

1
String pat = "<option\svalue=".{1,15}?">.{1,10}?\s\d\s.{1,5}?\s.{1,5}?\s(.{1,10}?)\&nbsp\;EUR</option>";
Regex r = new Regex(pat, RegexOptions.IgnoreCase);
Match m = r.Match(test);
Group ad1 = m.Groups[1];
String out = ad1 +"";
0

Provided your input is strictly just the option markup

<option value="28.5.2011|2">28.maj. 2 dni od 109,00&nbsp;EUR</option>
<option value="27.8.2011|2">27.avg. 2 dni od 109,00&nbsp;EUR</option>

The following works:

"([^\|]+)\|([^"])">.*?(\d+),

Note: This is a very specific Regex and I'm not familiar with C#. So if you need exact code, someone else will have to provide it. Nonetheless, for that input, the RegEx above works.

Jason McCreary
  • 71,546
  • 23
  • 135
  • 174
  • thx for answer but i get error. So i write this: \d+((.\d+)+(,\d+)?)? Is ok? – senzacionale Apr 21 '11 at 15:51
  • Which error exactly? The [regex](http://www.regular-expressions.info/) works OK with your very limited data set on [nregex.com](http://www.nregex.com) and [regexhero.net/tester](http://www.regexhero.net/tester). You probably just need to properly [take care of the quotes and escape sequences](http://stackoverflow.com/questions/5179389/at-sign-in-file-path-string/5179393#5179393 "escaping behavior of strings") to use the presented string in your code… – mousio Apr 21 '11 at 22:28