Andy Evans
Andy Evans

Reputation: 7176

.NET Regex - Find text between two characters within a single or multiple line block of text

I have been monkeying with the following regex expression:

(\b\*)\w+(\*\b)

What I wanted to do was extract

^vitae^

from

Nam vestibulum hendrerit justo. Quisque ^vitae^ libero magna. Curabitur pretium eros ut augue ullamcorper feugiat. Aenean blandit libero vitae nunc sodales pharetra.

But what I seem to get is that regex found the text in question and returns the all of the text in the sentence as opposed to just

^vitae^

Any help would be greatly appreciated

Thanks!

Upvotes: 0

Views: 859

Answers (2)

James Kyburz
James Kyburz

Reputation: 14453

To match any text between ^

@"\^([^^]*)\^")

//matchs ^ anything that isn't ^ and finally ^

It also matches line breaks if there are any

Upvotes: 2

Qtax
Qtax

Reputation: 33908

What about this expression:

@"\^\w+\^"

Upvotes: 1

Related Questions