简体   繁体   中英

parse data with regular expression

<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

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 +"";

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM