Question

I want to filter the following strings using Regular expression in C#.

+CUSD: 2,"Your account balance is BDT 00.00 valid till 02/05/14. Dial *789*1*1# to get daily General Health Tips,Charge Tk 1.73/SMS", 15

+CUSD: 1,"1 Call Block
2 Mobile Service
3 Infotainment
4 Recharge
5 Roaming
6 Internet
7 Product & Promotion
8 Account Info
9 GP STAR", 15

The first one is single line. Second one is multiline.

Regex regex1 = new Regex("\\+CUSD: (\\d+),\"(.*?)\", (\\d+)\\r\\n", RegexOptions.Multiline);

This Filter the first string but not the other.

What will be the common filter for both string?

Was it helpful?

Solution

Use RegexOptions.SingleLine instead.

From the docs:

Singleline Specifies single-line mode. Changes the meaning of the dot (.) so it matches every character (instead of every character except \n).

OTHER TIPS

Consider the following Regex...

\+CUSD: (\d+),\"[\s\S]*?\", (\d+)

Good Luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top