Qentinios
Qentinios

Reputation: 89

Regex end when character appears

/index.php?option=com_phocagallery&view=category&id=54:jubilaci-2014&Itemid=57"><img src="/./images/phocagallery/jubilaci2014/thumbs/phoca_thumb_m_zbiorwka zbowice kopiowanie.jpg" alt="Jubilaci 2014" style="border:0" />

/index.php?option=com_phocagallery&view=category&id=52:obszar-funkcjonalny-kluczbork-namysw-olesno&Itemid=57"><img src="/./images/phocagallery/obszarfunkcjonalny/thumbs/phoca_thumb_m_dsc_1005retusz kopiowanie.jpg" alt="Obszar Funkcjonalny Kluczbork-Namysłów-Olesno" style="border:0" />

/index.php?option=com_phocagallery&view=category&id=39:szkolenie-z-obrony-cywilnej&Itemid=57" class="category">Szkolenie z Obrony Cywilnej

I get such list, and i want to get from this only link, like this:

/index.php?option=com_phocagallery&view=category&id=26:jubilaci-2011&Itemid=57

How can I do it using Regex? Maybe how to get everything before character, in my case it would be:

"

I have tried st like this:

.*">

But it doesn't work as i want to.

Upvotes: 1

Views: 40

Answers (2)

Heinzi
Heinzi

Reputation: 172270

Here's a solution without lookahead:

^[^"]+
  • ^: Start of the line,
  • [^"]: all characters that are not double quotes,
  • +: at least one those characters (greedy = as many as possible).

However, since you have tagged your question as C#, you could just split on " and take the first part -- no regular expression required:

var result = myString.Split('"')[0];

Upvotes: 2

Avinash Raj
Avinash Raj

Reputation: 174706

You need to use a positive lookahead assertion.

@"(?m)^.*?(?="")"

It matches all the characters from the start upto the first " double quotes.

DEMO

Upvotes: 1

Related Questions